Xcos java tests: update them for Xcos6 60/17360/3
Clément DAVID [Wed, 21 Oct 2015 08:42:57 +0000 (10:42 +0200)]
Change-Id: Ia462d9e02dc4e196321650c2f8fc3ac871eeac97

12 files changed:
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/XcosTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/block/SortPortsTest.java [deleted file]
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/graph/DiagramComparatorTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/graph/ScicosParametersTest.java [deleted file]
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/graph/model/XcosCellFactoryTest.java [new file with mode: 0644]
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/port/command/CommandPortTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/port/control/ControlPortTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/port/input/ExplicitInputPortTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/port/input/ImplicitInputPortTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/port/output/ExplicitOutputPortTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/port/output/ImplicitOutputPortTest.java
scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/utils/FileTypeTest.java

index cdaa0fe..dc7969b 100644 (file)
@@ -14,6 +14,7 @@ package org.scilab.tests.modules.xcos;
 
 import static org.junit.Assert.assertTrue;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.scilab.modules.xcos.Xcos;
 
@@ -22,12 +23,17 @@ import org.scilab.modules.xcos.Xcos;
  */
 public class XcosTest {
 
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+    }
+
     /**
      * Be careful when modifying the tradename and version.
      */
     @Test
     public void checkVersion() {
         assertTrue(Xcos.TRADENAME.compareTo("Xcos") == 0);
-        assertTrue(Xcos.VERSION.compareTo("1.0") == 0);
+        assertTrue(Xcos.VERSION.compareTo("2.0") == 0);
     }
 }
diff --git a/scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/block/SortPortsTest.java b/scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/block/SortPortsTest.java
deleted file mode 100644 (file)
index 5cb1b23..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2012 - Scilab Enterprises - Clement DAVID
- *
- * 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.xcos.block;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.scilab.modules.xcos.block.BasicBlock;
-import org.scilab.modules.xcos.port.BasicPort;
-import org.scilab.modules.xcos.port.command.CommandPort;
-import org.scilab.modules.xcos.port.control.ControlPort;
-import org.scilab.modules.xcos.port.input.ExplicitInputPort;
-import org.scilab.modules.xcos.port.input.ImplicitInputPort;
-import org.scilab.modules.xcos.port.input.InputPort;
-import org.scilab.modules.xcos.port.output.ExplicitOutputPort;
-import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
-import org.scilab.modules.xcos.port.output.OutputPort;
-
-public class SortPortsTest {
-
-    @Test
-    public void checkEmpty() {
-        final ArrayList<Object> children = new ArrayList<Object>();
-        BasicBlock.sort(children);
-
-        Assert.assertEquals(children, Collections.EMPTY_LIST);
-        assertRightOrder(children);
-    }
-
-    @Test
-    public void checkAlone() {
-        checkSingleInstance(new ExplicitInputPort());
-        checkSingleInstance(new ExplicitOutputPort());
-        checkSingleInstance(new ControlPort());
-        checkSingleInstance(new CommandPort());
-    }
-
-    private void checkSingleInstance(Object instance) {
-        final ArrayList<Object> children = new ArrayList<Object>();
-        children.add(instance);
-
-        BasicBlock.sort(children);
-
-        Assert.assertEquals(children, Collections.singletonList(instance));
-        assertRightOrder(children);
-    }
-
-    @Test
-    public void checkMulti() throws InstantiationException, IllegalAccessException {
-        checkMultiInstance(ExplicitInputPort.class);
-        checkMultiInstance(ExplicitOutputPort.class);
-        checkMultiInstance(ControlPort.class);
-        checkMultiInstance(CommandPort.class);
-
-    }
-
-    private void checkMultiInstance(final Class <? extends BasicPort > klass) throws InstantiationException, IllegalAccessException {
-        final ArrayList<Object> children = new ArrayList<Object>();
-
-        final int size = (int) Math.random() * 10;
-        for (int i = 0; i < size; i++) {
-            children.add(klass.newInstance());
-        }
-
-        final ArrayList<Object> sorted = new ArrayList<Object>(children);
-        BasicBlock.sort(sorted);
-
-        Assert.assertEquals(children, sorted);
-        assertRightOrder(sorted);
-    }
-
-    @Test
-    public void sortPortsTwice() {
-        final ArrayList<Object> children = new ArrayList<Object>();
-        fillRandomly(children);
-
-        final ArrayList<Object> sorted = new ArrayList<Object>(children);
-        BasicBlock.sort(sorted);
-        assertRightOrder(sorted);
-
-        final ArrayList<Object> sortedTwice = new ArrayList<Object>(sorted);
-        BasicBlock.sort(sortedTwice);
-
-        Assert.assertEquals(sorted, sortedTwice);
-    }
-
-    private void fillRandomly(final List<Object> children) {
-        final int size = (int) (Math.random() * 10) + 3;
-
-        for (int i = 0; i < size; i++) {
-            final int type = (int) (Math.random() * 6);
-
-            final BasicPort p;
-            switch (type) {
-                case 0:
-                    p = new ExplicitInputPort();
-                    break;
-                case 1:
-                    p = new ImplicitInputPort();
-                    break;
-                case 2:
-                    p = new ExplicitOutputPort();
-                    break;
-                case 3:
-                    p = new ImplicitOutputPort();
-                    break;
-                case 4:
-                    p = new ControlPort();
-                    break;
-                case 5:
-                    p = new CommandPort();
-                    break;
-                default:
-                    p = null;
-                    break;
-            }
-
-            children.add(p);
-        }
-    }
-
-    private void assertRightOrder(final List<Object> children) {
-        int typeIndex = 0;
-
-        for (Object object : children) {
-            switch (typeIndex) {
-                case 0:
-                    if (object instanceof InputPort) {
-                        break;
-                    }
-                    typeIndex++;
-                case 1:
-                    if (object instanceof OutputPort) {
-                        break;
-                    }
-                    typeIndex++;
-                case 2:
-                    if (object instanceof ControlPort) {
-                        break;
-                    }
-                    typeIndex++;
-                case 3:
-                    if (object instanceof CommandPort) {
-                        break;
-                    }
-                    typeIndex++;
-
-                default:
-                    Assert.fail("children is not ordered");
-                    break;
-            }
-        }
-    }
-}
index 18a7031..66bf773 100644 (file)
@@ -20,17 +20,21 @@ import java.util.PriorityQueue;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
 import org.scilab.modules.xcos.Xcos;
 import org.scilab.modules.xcos.block.SuperBlock;
 import org.scilab.modules.xcos.graph.DiagramComparator;
-import org.scilab.modules.xcos.graph.SuperBlockDiagram;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 
 public class DiagramComparatorTest {
+    private JavaController controller;
 
     @Before
     public void loadLibrary() {
         System.loadLibrary("scilab");
+        controller = new JavaController();
     }
 
     @Test
@@ -39,14 +43,14 @@ public class DiagramComparatorTest {
             return;
         }
 
-        final PriorityQueue<XcosDiagram> sorted = new PriorityQueue<XcosDiagram>(1, DiagramComparator.getInstance());
+        final PriorityQueue<XcosDiagram> sorted = new PriorityQueue<XcosDiagram>(1, new DiagramComparator());
         final ArrayList<XcosDiagram> testVector = new ArrayList<XcosDiagram>();
 
         /*
          * Init test vector
          */
         for (int i = 0; i < 20; i++) {
-            testVector.add(new XcosDiagram());
+            testVector.add(new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM));
         }
 
         /*
@@ -72,14 +76,15 @@ public class DiagramComparatorTest {
             return;
         }
 
-        final PriorityQueue<XcosDiagram> sorted = new PriorityQueue<XcosDiagram>(1, DiagramComparator.getInstance());
+        final PriorityQueue<XcosDiagram> sorted = new PriorityQueue<XcosDiagram>(1, new DiagramComparator());
         final ArrayList<XcosDiagram> testVector = new ArrayList<XcosDiagram>();
 
         /*
          * Init test vector
          */
         for (int i = 0; i < 20; i++) {
-            testVector.add(new SuperBlockDiagram());
+            SuperBlock blk = new SuperBlock(controller.createObject(Kind.BLOCK));
+            testVector.add(new XcosDiagram(blk.getUID(), blk.getKind()));
         }
 
         /*
@@ -109,27 +114,25 @@ public class DiagramComparatorTest {
         /*
          * Init test vector
          */
-        XcosDiagram root1 = new XcosDiagram();
+        XcosDiagram root1 = new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM);
         root1.installListeners();
-        XcosDiagram root2 = new XcosDiagram();
+        XcosDiagram root2 = new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM);
         root2.installListeners();
 
         /*
          * First child
          */
-        SuperBlock r1b1 = new SuperBlock();
+        SuperBlock r1b1 = new SuperBlock(controller.createObject(Kind.BLOCK));
         root1.addCell(r1b1);
 
-        SuperBlockDiagram r1diag1 = new SuperBlockDiagram(r1b1);
+        XcosDiagram r1diag1 = new XcosDiagram(r1b1.getUID(), r1b1.getKind());
         r1diag1.installListeners();
-        r1diag1.installSuperBlockListeners();
 
-        SuperBlock r1diag1b1 = new SuperBlock();
+        SuperBlock r1diag1b1 = new SuperBlock(controller.createObject(Kind.BLOCK));
         r1diag1.addCell(r1diag1b1);
 
-        SuperBlockDiagram r1diag1b1diag1 = new SuperBlockDiagram(r1diag1b1);
+        XcosDiagram r1diag1b1diag1 = new XcosDiagram(r1diag1b1.getUID(), r1diag1b1.getKind());
         r1diag1b1diag1.installListeners();
-        r1diag1b1diag1.installSuperBlockListeners();
 
         /*
          * test vector
@@ -164,9 +167,16 @@ public class DiagramComparatorTest {
         for (XcosDiagram d : diags) {
             int currentDepth = 0;
 
-            while (d instanceof SuperBlockDiagram) {
+            long uid = d.getUID();
+            Kind kind = d.getKind();
+            while (kind == Kind.BLOCK) {
                 currentDepth++;
-                d = ((SuperBlockDiagram) d).getContainer().getParentDiagram();
+
+                long[] refUID = new long[1];
+                controller.getObjectProperty(uid, kind, ObjectProperties.PARENT_BLOCK, refUID);
+
+                uid = refUID[0];
+                kind = controller.getKind(refUID[0]);
             }
 
             assert currentDepth >= depth;
@@ -186,40 +196,36 @@ public class DiagramComparatorTest {
         /*
          * Init test vector
          */
-        XcosDiagram root1 = new XcosDiagram();
+        XcosDiagram root1 = new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM);
         root1.installListeners();
-        XcosDiagram root2 = new XcosDiagram();
+        XcosDiagram root2 = new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM);
         root2.installListeners();
 
         /*
          * First child
          */
-        SuperBlock r1b1 = new SuperBlock();
+        SuperBlock r1b1 = new SuperBlock(controller.createObject(Kind.BLOCK));
         root1.addCell(r1b1);
-        SuperBlock r2b1 = new SuperBlock();
+        SuperBlock r2b1 = new SuperBlock(controller.createObject(Kind.BLOCK));
         root1.addCell(r2b1);
 
-        SuperBlockDiagram r1diag1 = new SuperBlockDiagram(r1b1);
+        XcosDiagram r1diag1 = new XcosDiagram(r1b1.getUID(), r1b1.getKind());
         r1diag1.installListeners();
-        r1diag1.installSuperBlockListeners();
-        SuperBlockDiagram r2diag1 = new SuperBlockDiagram(r2b1);
+        XcosDiagram r2diag1 = new XcosDiagram(r2b1.getUID(), r2b1.getKind());
         r2diag1.installListeners();
-        r2diag1.installSuperBlockListeners();
 
         /*
          * Second child
          */
-        SuperBlock r1b2 = new SuperBlock();
+        SuperBlock r1b2 = new SuperBlock(controller.createObject(Kind.BLOCK));
         root1.addCell(r1b2);
-        SuperBlock r2b2 = new SuperBlock();
+        SuperBlock r2b2 = new SuperBlock(controller.createObject(Kind.BLOCK));
         root1.addCell(r2b2);
 
-        SuperBlockDiagram r1diag2 = new SuperBlockDiagram(r1b2);
+        XcosDiagram r1diag2 = new XcosDiagram(r1b2.getUID(), r1b2.getKind());
         r1diag2.installListeners();
-        r1diag2.installSuperBlockListeners();
-        SuperBlockDiagram r2diag2 = new SuperBlockDiagram(r2b2);
+        XcosDiagram r2diag2 = new XcosDiagram(r2b2.getUID(), r2b2.getKind());
         r2diag2.installListeners();
-        r2diag2.installSuperBlockListeners();
 
         /*
          * test vector
@@ -265,7 +271,7 @@ public class DiagramComparatorTest {
 
         while (it.hasNext()) {
             XcosDiagram diag = it.next();
-            assert diag instanceof SuperBlockDiagram;
+            assert diag.getKind() == Kind.BLOCK;
         }
     }
 
@@ -281,28 +287,26 @@ public class DiagramComparatorTest {
         /*
          * Init test vector
          */
-        XcosDiagram root = new XcosDiagram();
+        XcosDiagram root = new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM);
         root.installListeners();
 
         /*
          * First child
          */
-        SuperBlock b1 = new SuperBlock();
+        SuperBlock b1 = new SuperBlock(controller.createObject(Kind.BLOCK));
         root.addCell(b1);
 
-        SuperBlockDiagram diag1 = new SuperBlockDiagram(b1);
+        XcosDiagram diag1 = new XcosDiagram(b1.getUID(), b1.getKind());
         diag1.installListeners();
-        diag1.installSuperBlockListeners();
 
         /*
          * Second child
          */
-        SuperBlock b2 = new SuperBlock();
+        SuperBlock b2 = new SuperBlock(controller.createObject(Kind.BLOCK));
         root.addCell(b2);
 
-        SuperBlockDiagram diag2 = new SuperBlockDiagram(b2);
+        XcosDiagram diag2 = new XcosDiagram(b2.getUID(), b2.getKind());
         diag2.installListeners();
-        diag2.installSuperBlockListeners();
 
         /*
          * test vector
diff --git a/scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/graph/ScicosParametersTest.java b/scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/graph/ScicosParametersTest.java
deleted file mode 100644 (file)
index ac1fdf6..0000000
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2010 - DIGITEO - Clement DAVID
- *
- * 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.xcos.graph;
-
-import java.awt.GraphicsEnvironment;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyVetoException;
-import java.beans.VetoableChangeListener;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.scilab.modules.xcos.graph.ScicosParameters;
-
-/**
- * Test the behavior of the {@link ScicosParameters} class.
- *
- * We are checking the class behavior by using introspection.
- */
-public class ScicosParametersTest {
-    private static final String[] FIELDS;
-    private static final Field[] DEFAULT_VALUES;
-    private static final Method[] GETTERS;
-    private static final Method[] SETTERS;
-
-    @Before
-    public void loadLibrary() {
-        System.loadLibrary("scilab");
-    }
-
-    /**
-     * Initialize FIELDS, GETTERS and SETTERS and DEFAULT_VALUES.
-     */
-    static {
-        ArrayList<String> fields = new ArrayList<String>();
-        ArrayList<Method> setters = new ArrayList<Method>();
-        ArrayList<Method> getters = new ArrayList<Method>();
-        ArrayList<Field> default_values = new ArrayList<Field>();
-        /*
-         * First pass for getting SETTERS and FIELDS
-         */
-        for (Method m : ScicosParameters.class.getMethods()) {
-            if (m.getName().startsWith("set")) {
-                char[] field = m.getName().replaceFirst("set", "").toCharArray();
-                char firstChar = field[0];
-                field[0] = Character.toLowerCase(firstChar);
-
-                fields.add(new String(field));
-                setters.add(m);
-            }
-        }
-
-        /*
-         * Second pass for getting GETTERS and DEFAULT_VALUES
-         */
-        for (String f : fields) {
-            /*
-             * Getters
-             */
-            StringBuilder getter = new StringBuilder(f);
-            char firstChar = f.charAt(0);
-            getter.delete(0, 1);
-            getter.insert(0, Character.toUpperCase(firstChar));
-            getter.insert(0, "get");
-            String name = getter.toString();
-
-            for (Method m : ScicosParameters.class.getMethods()) {
-                if (m.getName().equals(name)) {
-                    getters.add(m);
-                    break;
-                }
-            }
-
-            /*
-             * Default values
-             */
-            StringBuilder constant = new StringBuilder(f);
-            for (int i = 0; i < constant.length(); i++) {
-                char c = constant.charAt(i);
-                if (Character.isUpperCase(c)) {
-                    constant.insert(i, "_");
-                    i++;
-                }
-            }
-            String field = constant.toString().toUpperCase();
-            try {
-                Field defaultValue = ScicosParameters.class.getDeclaredField(field);
-                default_values.add(defaultValue);
-            } catch (SecurityException e) {
-                throw new IllegalAccessError(e.toString());
-            } catch (NoSuchFieldException e) {
-                throw new IllegalAccessError(e.toString());
-            }
-        }
-
-        FIELDS = fields.toArray(new String[fields.size()]);
-        SETTERS = setters.toArray(new Method[setters.size()]);
-        GETTERS = getters.toArray(new Method[getters.size()]);
-        DEFAULT_VALUES = default_values.toArray(new Field[default_values.size()]);
-    }
-
-    @Test
-    public void checkNumberOfField() {
-        assert FIELDS.length == SETTERS.length;
-        assert FIELDS.length == GETTERS.length;
-        assert FIELDS.length == DEFAULT_VALUES.length;
-    }
-
-    @Test
-    public void checkInitValues() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-        if (GraphicsEnvironment.isHeadless()) {
-            return;
-        }
-
-        ScicosParameters obj = new ScicosParameters();
-
-        for (int i = 0; i < DEFAULT_VALUES.length; i++) {
-            Field f = DEFAULT_VALUES[i];
-            Method m = GETTERS[i];
-
-            final Object result = m.invoke(obj, (Object[]) null);
-            final Object reference = f.get(null);
-            assert result.equals(reference);
-        }
-    }
-
-    @Test
-    public void checkBeansNamedProperties() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
-        if (GraphicsEnvironment.isHeadless()) {
-            return;
-        }
-
-        for (int i = 0; i < DEFAULT_VALUES.length; i++) {
-            Field f = DEFAULT_VALUES[i];
-            String field = FIELDS[i];
-
-            // Check existence (will throw an exception)
-            Field change = ScicosParameters.class.getDeclaredField(f.getName() + "_CHANGE");
-
-            // Check value (field)
-            assert change.get(null).equals(field);
-        }
-    }
-
-    @Test
-    public void checkBeansPropertyChangeEvent() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
-        if (GraphicsEnvironment.isHeadless()) {
-            return;
-        }
-
-        ScicosParameters obj = new ScicosParameters();
-        final List<PropertyChangeEvent> receivedEvents = new ArrayList<PropertyChangeEvent>();
-
-        obj.addPropertyChangeListener(new PropertyChangeListener() {
-            @Override
-            public void propertyChange(PropertyChangeEvent evt) {
-                receivedEvents.add(evt);
-            }
-        });
-
-        /*
-         * Update fields
-         */
-        for (int i = 0; i < DEFAULT_VALUES.length; i++) {
-            final Method set = SETTERS[i];
-            final Field defaultValue = DEFAULT_VALUES[i];
-
-            Object newValue = null;
-            if (defaultValue.getType().equals(double.class)) {
-                newValue = defaultValue.getDouble(null) + 1;
-            } else if (defaultValue.getType().equals(int.class)) {
-                newValue = defaultValue.getInt(null) + 1;
-            } else if (defaultValue.getType().equals(String.class)) {
-                newValue = ((String) defaultValue.get(null)).concat("1");
-            } else if (defaultValue.getType().isArray()) {
-                Object array = defaultValue.get(null);
-                final Class <? extends Object > type = defaultValue.getType().getComponentType();
-                final Object value;
-
-                final int arrayLength = Array.getLength(array);
-                value = Array.newInstance(type, arrayLength + 1);
-
-                /*
-                 * Copying values
-                 */
-                for (int j = 0; j < arrayLength; j++) {
-                    Array.set(value, j, Array.get(array, j));
-                }
-
-                /*
-                 * The latest value must be equal to the previous one or to the
-                 * type's default value
-                 */
-                final Object o;
-                if (arrayLength > 0) {
-                    o = Array.get(array, arrayLength - 1);
-                } else {
-                    o = type.newInstance();
-                }
-                Array.set(value, arrayLength, o);
-
-                newValue = value;
-            }
-
-            set.invoke(obj, newValue);
-        }
-
-        /*
-         * Check for modification events
-         */
-        for (int i = 0; i < DEFAULT_VALUES.length; i++) {
-            final Method get = GETTERS[i];
-            final PropertyChangeEvent evt = receivedEvents.get(i);
-
-            Object newValue = get.invoke(obj);
-            assert newValue.equals(evt.getNewValue());
-        }
-    }
-
-    @Test
-    public void checkBeansVetoableChangeEvent() throws IllegalArgumentException, IllegalAccessException, InstantiationException {
-        if (GraphicsEnvironment.isHeadless()) {
-            return;
-        }
-
-        ScicosParameters obj = new ScicosParameters();
-        final List<PropertyVetoException> receivedExceptions = new ArrayList<PropertyVetoException>();
-
-        obj.addVetoableChangeListener(new VetoableChangeListener() {
-            @Override
-            public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
-                // always throw exception
-                throw new PropertyVetoException(evt.getPropertyName(), evt);
-            }
-        });
-
-        /*
-         * Update fields
-         */
-        for (int i = 0; i < DEFAULT_VALUES.length; i++) {
-            final Method set = SETTERS[i];
-            final Field defaultValue = DEFAULT_VALUES[i];
-
-            Object newValue = null;
-            if (defaultValue.getType().equals(double.class)) {
-                newValue = defaultValue.getDouble(null) + 1;
-            } else if (defaultValue.getType().equals(int.class)) {
-                newValue = defaultValue.getInt(null) + 1;
-            } else if (defaultValue.getType().equals(String.class)) {
-                newValue = ((String) defaultValue.get(null)).concat("1");
-            } else if (defaultValue.getType().isArray()) {
-                Object array = defaultValue.get(null);
-                final Class <? extends Object > type = defaultValue.getType().getComponentType();
-                final Object value;
-
-                final int arrayLength = Array.getLength(array);
-                value = Array.newInstance(type, arrayLength + 1);
-
-                /*
-                 * Copying values
-                 */
-                for (int j = 0; j < arrayLength; j++) {
-                    Array.set(value, j, Array.get(array, j));
-                }
-
-                /*
-                 * The latest value must be equal to the previous one or to the
-                 * type's default value
-                 */
-                final Object o;
-                if (arrayLength > 0) {
-                    o = Array.get(array, arrayLength - 1);
-                } else {
-                    o = type.newInstance();
-                }
-                Array.set(value, arrayLength, o);
-
-                newValue = value;
-            }
-
-            try {
-                set.invoke(obj, newValue);
-            } catch (InvocationTargetException e) {
-                receivedExceptions.add((PropertyVetoException) e.getTargetException());
-            }
-        }
-
-        /*
-         * Check for received PropertyVetoException
-         */
-        assert receivedExceptions.size() == DEFAULT_VALUES.length;
-        for (int i = 0; i < DEFAULT_VALUES.length; i++) {
-            final String field = FIELDS[i];
-            final PropertyVetoException e = receivedExceptions.get(i);
-
-            assert e.getMessage().equals(field);
-        }
-    }
-
-    /**
-     * Call all public methods through introspection
-     *
-     * @param args
-     *            not used
-     * @throws InvocationTargetException
-     * @throws IllegalAccessException
-     * @throws IllegalArgumentException
-     */
-    public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-        Object obj = new ScicosParametersTest();
-        Method[] tests = ScicosParametersTest.class.getDeclaredMethods();
-        for (Method method : tests) {
-            int modifiers = method.getModifiers();
-            if ((modifiers | Modifier.STATIC) != modifiers) {
-                method.invoke(obj, (Object[]) null);
-            }
-        }
-    }
-}
diff --git a/scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/graph/model/XcosCellFactoryTest.java b/scilab/modules/xcos/tests/java/org/scilab/tests/modules/xcos/graph/model/XcosCellFactoryTest.java
new file mode 100644 (file)
index 0000000..e793f83
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - Scilab Enterprises - Clement DAVID
+ *
+ * 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.xcos.graph.model;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.EnumSet;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.graph.model.BlockInterFunction;
+import org.scilab.modules.xcos.graph.model.XcosCellFactory;
+
+public class XcosCellFactoryTest {
+    private JavaController controller;
+
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+        controller = new JavaController();
+    }
+
+    @Test
+    public void createOneSpecificBlock() {
+        final String interfaceFunction = "BIGSOM_f";
+        BasicBlock blk = XcosCellFactory.createBlock(controller, XcosCellFactory.lookForInterfunction(interfaceFunction), interfaceFunction,
+                         controller.createObject(Kind.BLOCK));
+
+        assert blk.getStyle().contains(interfaceFunction);
+    }
+
+    @Test
+    public void createAllSpecificBlocks() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException,
+        IllegalArgumentException, InvocationTargetException {
+        EnumSet<BlockInterFunction> blocks = EnumSet.allOf(BlockInterFunction.class);
+        blocks.remove(BlockInterFunction.BASIC_BLOCK);
+
+        for (BlockInterFunction b : blocks) {
+            Constructor<? extends BasicBlock> cstr = b.getKlass().getConstructor(Long.TYPE);
+            BasicBlock blk = cstr.newInstance(controller.createObject(Kind.BLOCK));
+
+            // the block should have no children
+            assert blk.getChildCount() == 0;
+        }
+    }
+}
index 7a9908c..a3fe487 100644 (file)
 
 package org.scilab.tests.modules.xcos.port.command;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.command.CommandPort;
-import org.junit.*;
 
 /**
  * Unit test for {@link CommandPort}
  */
 public class CommandPortTest {
     public static final int DEFAULT_PORTSIZE = 8;
+    private JavaController controller;
+
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+        controller = new JavaController();
+    }
 
     @Test
     public void checkType() {
-        CommandPort port = new CommandPort();
+        CommandPort port = new CommandPort(controller.createObject(Kind.PORT));
         assert port.getType() == null;
     }
 
     @Test
     public void checkDefaultOrientation() {
-        CommandPort port = new CommandPort();
+        CommandPort port = new CommandPort(controller.createObject(Kind.PORT));
         assert port.getOrientation() == Orientation.SOUTH;
     }
 
     @Test
     public void checkStyle() {
-        CommandPort port = new CommandPort();
+        CommandPort port = new CommandPort(controller.createObject(Kind.PORT));
         assert port.getStyle().contains("CommandPort");
     }
 
     @Test
-    public void checkTypeName() {
-        CommandPort port = new CommandPort();
-        assert port.getTypeName().equals("CommandPort");
-    }
-
-    @Test
     public void checkClassHierarchy() {
-        CommandPort port = new CommandPort();
+        CommandPort port = new CommandPort(controller.createObject(Kind.PORT));
         assert port instanceof BasicPort;
     }
 
     @Test
     public void checkDefaultGeometry() {
-        CommandPort port = new CommandPort();
+        CommandPort port = new CommandPort(controller.createObject(Kind.PORT));
         assert port.getGeometry().getWidth() == DEFAULT_PORTSIZE;
         assert port.getGeometry().getHeight() == DEFAULT_PORTSIZE;
     }
index cc07818..925e234 100644 (file)
 
 package org.scilab.tests.modules.xcos.port.control;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.control.ControlPort;
-import org.junit.*;
 
 /**
  * Unit test for {@link ControlPort}
  */
 public class ControlPortTest {
     public static final int DEFAULT_PORTSIZE = 8;
+    private JavaController controller;
+
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+        controller = new JavaController();
+    }
 
     @Test
     public void checkType() {
-        ControlPort port = new ControlPort();
+        ControlPort port = new ControlPort(controller.createObject(Kind.PORT));
         assert port.getType() == null;
     }
 
     @Test
     public void checkDefaultOrientation() {
-        ControlPort port = new ControlPort();
+        ControlPort port = new ControlPort(controller.createObject(Kind.PORT));
         assert port.getOrientation() == Orientation.NORTH;
     }
 
     @Test
     public void checkStyle() {
-        ControlPort port = new ControlPort();
+        ControlPort port = new ControlPort(controller.createObject(Kind.PORT));
         assert port.getStyle().contains("ControlPort");
     }
 
     @Test
-    public void checkTypeName() {
-        ControlPort port = new ControlPort();
-        assert port.getTypeName().equals("ControlPort");
-    }
-
-    @Test
     public void checkClassHierarchy() {
-        ControlPort port = new ControlPort();
+        ControlPort port = new ControlPort(controller.createObject(Kind.PORT));
         assert port instanceof BasicPort;
     }
 
     @Test
     public void checkDefaultGeometry() {
-        ControlPort port = new ControlPort();
+        ControlPort port = new ControlPort(controller.createObject(Kind.PORT));
         assert port.getGeometry().getWidth() == DEFAULT_PORTSIZE;
         assert port.getGeometry().getHeight() == DEFAULT_PORTSIZE;
     }
index 84d875a..6d9fffd 100644 (file)
 
 package org.scilab.tests.modules.xcos.port.input;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.port.BasicPort;
-import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.BasicPort.Type;
+import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.input.ExplicitInputPort;
 import org.scilab.modules.xcos.port.input.InputPort;
-import org.junit.*;
 
 /**
  * Unit test for {@link ExplicitInputPort}
  */
 public class ExplicitInputPortTest {
     public static final int DEFAULT_PORTSIZE = 8;
+    private JavaController controller;
+
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+        controller = new JavaController();
+    }
 
     @Test
     public void checkType() {
-        ExplicitInputPort port = new ExplicitInputPort();
+        ExplicitInputPort port = new ExplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getType() == Type.EXPLICIT;
     }
 
     @Test
     public void checkDefaultOrientation() {
-        ExplicitInputPort port = new ExplicitInputPort();
+        ExplicitInputPort port = new ExplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getOrientation() == Orientation.WEST;
     }
 
     @Test
     public void checkStyle() {
-        ExplicitInputPort port = new ExplicitInputPort();
+        ExplicitInputPort port = new ExplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getStyle().contains("ExplicitInputPort");
     }
 
     @Test
-    public void checkTypeName() {
-        ExplicitInputPort port = new ExplicitInputPort();
-        assert port.getTypeName().equals("ExplicitInputPort");
-    }
-
-    @Test
     public void checkClassHierarchy() {
-        ExplicitInputPort port = new ExplicitInputPort();
+        ExplicitInputPort port = new ExplicitInputPort(controller.createObject(Kind.PORT));
         assert port instanceof InputPort;
         assert port instanceof BasicPort;
     }
 
     @Test
     public void checkDefaultGeometry() {
-        ExplicitInputPort port = new ExplicitInputPort();
+        ExplicitInputPort port = new ExplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getGeometry().getWidth() == DEFAULT_PORTSIZE;
         assert port.getGeometry().getHeight() == DEFAULT_PORTSIZE;
     }
index b65247b..69a6194 100644 (file)
 
 package org.scilab.tests.modules.xcos.port.input;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.port.BasicPort;
-import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.BasicPort.Type;
+import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.input.ImplicitInputPort;
 import org.scilab.modules.xcos.port.input.InputPort;
-import org.junit.*;
 
 /**
  * Unit test for {@link ImplicitInputPort}
  */
 public class ImplicitInputPortTest {
     public static final int DEFAULT_PORTSIZE = 8;
+    private JavaController controller;
+
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+        controller = new JavaController();
+    }
 
     @Test
     public void checkType() {
-        ImplicitInputPort port = new ImplicitInputPort();
+        ImplicitInputPort port = new ImplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getType() == Type.IMPLICIT;
     }
 
     @Test
     public void checkDefaultOrientation() {
-        ImplicitInputPort port = new ImplicitInputPort();
+        ImplicitInputPort port = new ImplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getOrientation() == Orientation.WEST;
     }
 
     @Test
     public void checkStyle() {
-        ImplicitInputPort port = new ImplicitInputPort();
+        ImplicitInputPort port = new ImplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getStyle().contains("ImplicitInputPort");
     }
 
     @Test
-    public void checkTypeName() {
-        ImplicitInputPort port = new ImplicitInputPort();
-        assert port.getTypeName().equals("ImplicitInputPort");
-    }
-
-    @Test
     public void checkClassHierarchy() {
-        ImplicitInputPort port = new ImplicitInputPort();
+        ImplicitInputPort port = new ImplicitInputPort(controller.createObject(Kind.PORT));
         assert port instanceof InputPort;
         assert port instanceof BasicPort;
     }
 
     @Test
     public void checkDefaultGeometry() {
-        ImplicitInputPort port = new ImplicitInputPort();
+        ImplicitInputPort port = new ImplicitInputPort(controller.createObject(Kind.PORT));
         assert port.getGeometry().getWidth() == DEFAULT_PORTSIZE;
         assert port.getGeometry().getHeight() == DEFAULT_PORTSIZE;
     }
index cdea844..aa3b42d 100644 (file)
 
 package org.scilab.tests.modules.xcos.port.output;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.port.BasicPort;
-import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.BasicPort.Type;
+import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.output.ExplicitOutputPort;
 import org.scilab.modules.xcos.port.output.OutputPort;
-import org.junit.*;
 
 /**
  * Unit test for {@link ExplicitOutputPort}
  */
 public class ExplicitOutputPortTest {
     public static final int DEFAULT_PORTSIZE = 8;
+    private JavaController controller;
+
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+        controller = new JavaController();
+    }
 
     @Test
     public void checkType() {
-        ExplicitOutputPort port = new ExplicitOutputPort();
+        ExplicitOutputPort port = new ExplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getType() == Type.EXPLICIT;
     }
 
     @Test
     public void checkDefaultOrientation() {
-        ExplicitOutputPort port = new ExplicitOutputPort();
+        ExplicitOutputPort port = new ExplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getOrientation() == Orientation.EAST;
     }
 
     @Test
     public void checkStyle() {
-        ExplicitOutputPort port = new ExplicitOutputPort();
+        ExplicitOutputPort port = new ExplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getStyle().contains("ExplicitOutputPort");
     }
 
     @Test
-    public void checkTypeName() {
-        ExplicitOutputPort port = new ExplicitOutputPort();
-        assert port.getTypeName().equals("ExplicitOutputPort");
-    }
-
-    @Test
     public void checkClassHierarchy() {
-        ExplicitOutputPort port = new ExplicitOutputPort();
+        ExplicitOutputPort port = new ExplicitOutputPort(controller.createObject(Kind.PORT));
         assert port instanceof OutputPort;
         assert port instanceof BasicPort;
     }
 
     @Test
     public void checkDefaultGeometry() {
-        ExplicitOutputPort port = new ExplicitOutputPort();
+        ExplicitOutputPort port = new ExplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getGeometry().getWidth() == DEFAULT_PORTSIZE;
         assert port.getGeometry().getHeight() == DEFAULT_PORTSIZE;
     }
index 3b548c6..e97fc06 100644 (file)
 
 package org.scilab.tests.modules.xcos.port.output;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.port.BasicPort;
-import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.BasicPort.Type;
+import org.scilab.modules.xcos.port.Orientation;
 import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
 import org.scilab.modules.xcos.port.output.OutputPort;
-import org.junit.*;
 
 /**
  * Unit test for {@link ImplicitOutputPort}
  */
 public class ImplicitOutputPortTest {
     public static final int DEFAULT_PORTSIZE = 8;
+    private JavaController controller;
+
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+        controller = new JavaController();
+    }
 
     @Test
     public void checkType() {
-        ImplicitOutputPort port = new ImplicitOutputPort();
+        ImplicitOutputPort port = new ImplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getType() == Type.IMPLICIT;
     }
 
     @Test
     public void checkDefaultOrientation() {
-        ImplicitOutputPort port = new ImplicitOutputPort();
+        ImplicitOutputPort port = new ImplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getOrientation() == Orientation.EAST;
     }
 
     @Test
     public void checkStyle() {
-        ImplicitOutputPort port = new ImplicitOutputPort();
+        ImplicitOutputPort port = new ImplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getStyle().contains("ImplicitOutputPort");
     }
 
     @Test
-    public void checkTypeName() {
-        ImplicitOutputPort port = new ImplicitOutputPort();
-        assert port.getTypeName().equals("ImplicitOutputPort");
-    }
-
-    @Test
     public void checkClassHierarchy() {
-        ImplicitOutputPort port = new ImplicitOutputPort();
+        ImplicitOutputPort port = new ImplicitOutputPort(controller.createObject(Kind.PORT));
         assert port instanceof OutputPort;
         assert port instanceof BasicPort;
     }
 
     @Test
     public void checkDefaultGeometry() {
-        ImplicitOutputPort port = new ImplicitOutputPort();
+        ImplicitOutputPort port = new ImplicitOutputPort(controller.createObject(Kind.PORT));
         assert port.getGeometry().getWidth() == DEFAULT_PORTSIZE;
         assert port.getGeometry().getHeight() == DEFAULT_PORTSIZE;
     }
index 0208d5f..82bc442 100644 (file)
 
 package org.scilab.tests.modules.xcos.utils;
 
+import java.awt.GraphicsEnvironment;
 import java.io.File;
 import java.io.IOException;
-import java.awt.GraphicsEnvironment;
 
-import org.junit.Test;
 import org.junit.Assume;
-
+import org.junit.Before;
+import org.junit.Test;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.io.XcosFileType;
 
-
 /**
  * Test the {@link XcosFileType} class.
  */
 public class FileTypeTest {
     private static final String XcosFileHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
 
+    @Before
+    public void loadLibrary() {
+        System.loadLibrary("scilab");
+    }
+
     @Test
     public void checkSupportedType() {
         assert XcosFileType.values().length == 4;
@@ -71,7 +77,9 @@ public class FileTypeTest {
     public void validateXcosFindFileType() throws Exception {
         Assume.assumeTrue(!GraphicsEnvironment.isHeadless());
         File tmp = File.createTempFile("xcosTest", XcosFileType.XCOS.getDottedExtension());
-        XcosFileType.XCOS.save(tmp.getCanonicalPath(), new XcosDiagram());
+
+        JavaController controller = new JavaController();
+        XcosFileType.XCOS.save(tmp.getCanonicalPath(), new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM));
 
         assert XcosFileType.XCOS == XcosFileType.findFileType(tmp);
 
@@ -82,7 +90,9 @@ public class FileTypeTest {
     public void validateZcosFindFileType() throws Exception {
         Assume.assumeTrue(!GraphicsEnvironment.isHeadless());
         File tmp = File.createTempFile("xcosTest", XcosFileType.ZCOS.getDottedExtension());
-        XcosFileType.ZCOS.save(tmp.getCanonicalPath(), new XcosDiagram());
+
+        JavaController controller = new JavaController();
+        XcosFileType.ZCOS.save(tmp.getCanonicalPath(), new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM));
 
         assert XcosFileType.ZCOS == XcosFileType.findFileType(tmp);