Dear all, Please be informed that, due to an important technical maintenance, the Gitlab server (git.list.lu) will not be available on Thursday April 22nd, from 9 A.M. to 1 P.M. (Luxembourg Time Zone). Thank you for your understanding.

Commit 33013909 authored by Nicolas Gilmard's avatar Nicolas Gilmard

Add JUnit test cases for TuioConcreteAdapter

parent 256a94cb
/**
* Copyright LIST Luxembourg Institue of Sciences and Technology, 2015.
* Copyright LIST Luxembourg Institute of Science and Technology, 2015.
* All rights reserved. If you wish to use this code for any purpose,
* please contact LIST's Technology Transfer Office : tto@tudor.lu
*/
......@@ -18,108 +18,68 @@ import java.util.Vector;
*/
public class TangibleObject
{
/**
* Enum which defines different types of objects recognised
*/
/** Enumeration of different types of objects recognised */
public enum Flag {OBJECT, CURSOR};
/**
* The unique object ID number that is assigned to each tangible object.
*/
/** The unique object ID number that is assigned to each tangible object. */
protected int objectId;
/**
* The flag which identify the type of the object.
*/
/** The flag which identify the type of the object. */
protected Flag flag;
/**
* the time since session start in seconds
*/
/** the time since session start in seconds */
protected long seconds = 0;
/**
* time fraction in microseconds
*/
/** time fraction in microseconds */
protected long microSeconds = 0;
/**
* The X-axis velocity value.
*/
/** The X-axis velocity value. */
protected float xSpeed;
/**
* The Y-axis velocity value.
*/
/** The Y-axis velocity value. */
protected float ySpeed;
/**
* The motion speed value.
*/
/** The motion speed value. */
protected float motionSpeed;
/**
* The motion acceleration value.
*/
/** The motion acceleration value. */
protected float motionAccel;
/**
* The rotation speed value.
*/
/** The rotation speed value. */
protected float rotationSpeed;
/**
* The rotation acceleration value.
*/
/** The rotation acceleration value. */
protected float rotationAccel;
/**
* A Vector of {@link Point} containing all the previous positions of the tangible object.
*/
/** A Vector of {@link Point} containing all the previous positions of the tangible object. */
protected Vector<Point> path;
/*
* Mayby use an enum for the several states ??
*/
/**
* Reflects the current state of the {@link TangibleObject}
*/
/** Reflects the current state of the {@link TangibleObject} */
protected int state;
/**
* Defines the ADDED state.
*/
/* Maybe use an enum for the different states
* enum State { ADDED, ACCELERATING, DECELERATING, STOPPED, REMOVED, ROTATING };
* */
/** Defines the ADDED state. */
public static final int ADDED = 0;
/**
* Defines the ACCELERATING state.
*/
/** Defines the ACCELERATING state. */
public static final int ACCELERATING = 1;
/**
* Defines the DECELERATING state.
*/
/** Defines the DECELERATING state. */
public static final int DECELERATING = 2;
/**
* Defines the STOPPED state.
*/
/** Defines the STOPPED state. */
public static final int STOPPED = 3;
/**
* Defines the REMOVED state.
*/
/** Defines the REMOVED state. */
public static final int REMOVED = 4;
/**
* Defines the ROTATING state.
*/
/** Defines the ROTATING state. */
public static final int ROTATING = 5;
/**
* Default constructor
*/
/** Default constructor */
public TangibleObject(int objectId, Flag flag, long seconds, long microSeconds, float xSpeed, float ySpeed, float motionSpeed, float motionAccel, float rotationSpeed, float rotationAccel, Vector<Point> path, int state) {
this.objectId = objectId;
this.flag = flag;
......@@ -383,5 +343,4 @@ public class TangibleObject
{
this.state = state;
}
}
/**
* Copyright LIST Luxembourg Institue of Sciences and Technology, 2015.
* Copyright LIST Luxembourg Institute of Science and Technology, 2015.
* All rights reserved. If you wish to use this code for any purpose,
* please contact LIST's Technology Transfer Office : tto@tudor.lu
*/
......@@ -14,7 +14,7 @@ import java.util.Vector;
/**
* {@link TangibleObjectBuilder} class used to construct a {@link TangibleObject}
* by providing methods to set all parameters and permutations thereof.
* by providing methods to set all parameters.
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 10 Feb 2015
* @version 1
......@@ -56,7 +56,7 @@ public class TangibleObjectBuilder
protected Vector<Point> path = new Vector<Point>();
/** Reflects the current state of the {@link TangibleObject} */
protected int state = 0;
protected int state = TangibleObject.ADDED;
/**
* Constructor setting the required fields of a tangibleObject
......@@ -208,7 +208,7 @@ public class TangibleObjectBuilder
* Method for building a {@link TangibleObject} with the
* values set by the builder.
* @return
* An instance of {@link TangibleObjectBuilder} as by the
* An instance of {@link TangibleObject} as by the
* values issued to the builder.
* @pre objectId and path != null
* @pre path contains at least one point
......
/**
* Copyright LIST Luxembourg Institue of Sciences and Technology, 2015.
* Copyright LIST Luxembourg Institute of Science and Technology, 2015.
* All rights reserved. If you wish to use this code for any purpose,
* please contact LIST's Technology Transfer Office : tto@tudor.lu
*/
......
/**
* Copyright LIST Luxembourg Institue of Sciences and Technology, 2015.
* Copyright LIST Luxembourg Institute of Science and Technology, 2015.
* All rights reserved. If you wish to use this code for any purpose,
* please contact LIST's Technology Transfer Office : tto@tudor.lu
*/
......
......@@ -93,12 +93,6 @@ public abstract class TangibleObjectManager
*/
public abstract void defineWidgets() throws BuildException;
/**
* {@inheritDoc} It will output several notices on {@link Level#INFO} to the {@link Logger}
* before issuing a call to the widget to which the dropped handle is mapped.
*/
/**
* Method ensuring that all mapped widgets are present on the
* table by querying the global state of the application.
......@@ -190,7 +184,6 @@ public abstract class TangibleObjectManager
cursorList.get(tangibleObject.getObjectId()).actionDrop(tangibleObject);
ensureConsistency();
break;
case OBJECT:
......@@ -223,6 +216,7 @@ public abstract class TangibleObjectManager
{
cursorList.remove(tangibleObject.getObjectId()).actionLift(tangibleObject);
}
break;
case OBJECT:
......@@ -271,5 +265,4 @@ public abstract class TangibleObjectManager
break;
}
}
}
\ No newline at end of file
......@@ -56,16 +56,16 @@ public class IDMapper
* conflicting. As cursors need to static assignation to physical objects, the handles,
* it was chosen to remap their ID. The remapping adds a constant to each ID as
* defined by the properties file.
* @param cursorID
* @param objectID
* The cursor ID to remap.
* @return
* The remapped cursor ID.
* @pre cursorID > 1024 (default in propertie's file)
* @post result > 0
* @pre cursorID >= 1024 (default in propertie's file)
* @post result >= 0
*/
public static int remapTangibleObjectID(int objectID)
{
Preconditions.checkArgument(objectID > 1024, "The provided ID must be greater than file in properties!");
Preconditions.checkArgument(objectID >= 1024, "The provided ID must be greater than file in properties!");
return objectID - Integer.parseInt(properties.getProperty("cursorIDRemappingConstant", "1024"));
}
......
......@@ -7,24 +7,20 @@ package lu.tudor.ssi.kiss.tui.widget;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import lu.tudor.ssi.kiss.tui.logging.EventLogger;
import lu.tudor.ssi.kiss.tui.utility.IDMapper;
import lu.tudor.ssi.kiss.tui.utility.Point;
import lu.tudor.ssi.kiss.tui.widget.builder.BaseBuilder;
import lu.tudor.ssi.kiss.tui.widget.corona.Corona;
import TUIO.TuioCursor;
import TUIO.TuioObject;
import com.google.common.collect.Multimap;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
/**
* A simple widget implementation which sets some default
* behaviour for common methods. It also servers as a
......@@ -65,9 +61,9 @@ public class BaseWidget
* Method invoked when a handle associated with the widget was moved.
* This default implementation will set the base and angle fields
* to the corresponding values and update the coronas of the
* handle that the {@link TuioObject} corresponds to.
* @param tuioObject
* The {@link TuioObject} that was triggering the move.
* handle that the {@link TangibleObject} corresponds to.
* @param tangibleObject
* The {@link TangibleObject} that was triggering the move.
*/
public void actionMove(TangibleObject tangibleObject)
{
......@@ -79,25 +75,6 @@ public class BaseWidget
tangibleObject.getAngle(), Math.signum(tangibleObject.getRotationSpeed())));
updateCoronas(tangibleObject.getObjectId());
}
/**
* Method invoked when a cursor associated with the widget was moved.
* This default implementation will set the base fields
* to the corresponding values and update the coronas of the
* handle that the {@link TuioCursor} corresponds to given its ID.
* @param tuioCursor
* The {@link TuioCursor} that was triggering the move.
*/
public void actionMove(TuioCursor tuioCursor)
{
EventLogger.getInstance().addCurInfo(tuioCursor.getCursorID(), tuioCursor.getX(),
tuioCursor.getY(), "move",
tuioCursor.getTuioTime().getTotalMilliseconds());
positions.put(IDMapper.remapCursorID(tuioCursor.getCursorID()),
new Point(tuioCursor.getX(), tuioCursor.getX(), 0));
updateCoronas(IDMapper.remapCursorID(tuioCursor.getCursorID()));
}
/**
* Method used to keep the conona's positions aligned with the base of the
......@@ -118,16 +95,16 @@ public class BaseWidget
/**
* Method invoked when the tangible is detected on the table surface for
* the first time. The {@link BaseWidget} instance is set to be active.
* @param tuioObject
* The {@link TuioObject} that was triggering the drop action.
* @param tangibleObject
* The {@link TangibleObject} that was triggering the drop action.
*/
public void actionDrop(TangibleObject tuioObject)
public void actionDrop(TangibleObject tangibleObject)
{
EventLogger.getInstance().addObjInfo(tuioObject.getObjectId(), tuioObject.getX(),
tuioObject.getY(), tuioObject.getAngle(), "down",
tuioObject.getTotalMilliseconds());
actionMove(tuioObject);
startDrawingIfAppropriate(tuioObject.getObjectId());
EventLogger.getInstance().addObjInfo(tangibleObject.getObjectId(), tangibleObject.getX(),
tangibleObject.getY(), tangibleObject.getAngle(), "down",
tangibleObject.getTotalMilliseconds());
actionMove(tangibleObject);
startDrawingIfAppropriate(tangibleObject.getObjectId());
}
/**
......@@ -143,37 +120,20 @@ public class BaseWidget
corona.onTable();
}
}
/**
* Method invoked when a cursor associated with this widget is
* detected on the surface for the first time. The
* {@link BaseWidget} instance is set to be active.
* @param tuioCursor
* The {@link TuioCursor} that was triggering the drop action.
*/
public void actionDrop(TuioCursor tuioCursor)
{
EventLogger.getInstance().addCurInfo(tuioCursor.getCursorID(), tuioCursor.getX(),
tuioCursor.getY(), "down",
tuioCursor.getTuioTime().getTotalMilliseconds());
actionMove(tuioCursor);
startDrawingIfAppropriate(IDMapper.remapCursorID(tuioCursor.getCursorID()));
}
/**
* Method invoked when the tangible is removed from the table surface. The
* {@link BaseWidget} instance will be set to no longer be active.
* @param tuioObject
* The TuioObject that was triggering the drop action.
* @param tangibleObject
* The TangibleObject that was triggering the drop action.
*/
public void actionLift(TangibleObject tuioObject)
public void actionLift(TangibleObject tangibleObject)
{
EventLogger.getInstance().addObjInfo(tuioObject.getObjectId(), tuioObject.getX(),
tuioObject.getY(), tuioObject.getAngle(), "up",
tuioObject.getTotalMilliseconds());
actionMove(tuioObject);
stopDrawing(tuioObject.getObjectId());
EventLogger.getInstance().addObjInfo(tangibleObject.getObjectId(), tangibleObject.getX(),
tangibleObject.getY(), tangibleObject.getAngle(), "up",
tangibleObject.getTotalMilliseconds());
actionMove(tangibleObject);
stopDrawing(tangibleObject.getObjectId());
}
/**
......@@ -189,23 +149,6 @@ public class BaseWidget
}
}
/**
* Method invoked when the cursor is removed from the table surface. The
* {@link BaseWidget} instance will be set to no longer be active or,
* depending on the allocation (dynamic or static) the widget might be
* removed from the dictionary altogether.
* @param tuioCursor
* The {@link TuioCursor} that was triggering the drop action.
*/
public void actionLift(TuioCursor tuioCursor)
{
EventLogger.getInstance().addCurInfo(tuioCursor.getCursorID(), tuioCursor.getX(),
tuioCursor.getY(), "up",
tuioCursor.getTuioTime().getTotalMilliseconds());
actionMove(tuioCursor);
stopDrawing(IDMapper.remapCursorID(tuioCursor.getCursorID()));
}
/**
* Draws a the visual feedback for any widget. The method will
* iterate through all coronas and call their <code>paint()</code>
......
package lu.list.itis.dkd.tui.adapter;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import lu.list.itis.dkd.tui.adapter.TangibleObject.Flag;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import lu.tudor.ssi.kiss.tui.TangibleApplication;
import lu.tudor.ssi.kiss.tui.TangibleObjectManager;
import lu.tudor.ssi.kiss.tui.exception.BuildException;
import lu.tudor.ssi.kiss.tui.utility.IDMapper;
import lu.tudor.ssi.kiss.tui.utility.Point;
import TUIO.TuioCursor;
import TUIO.TuioObject;
import TUIO.TuioPoint;
import TUIO.TuioTime;
import org.junit.Before;
import org.junit.Test;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
import java.util.logging.Logger;
public class TuioConcreteAdapterTest
{
private TuiAdapter tuiAdapter;
private String propertiesLocation = "test_properties.properties";
private TangibleApplication application;
/**
* Setting up resources for use in each test method.
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception
{
application = new TestTangibleApplication(propertiesLocation);
tuiAdapter = application.getAdapter();
}
/**
* Test method for {@link lu.tudor.ssi.kiss.tui.TangibleInterfaceManager#TangibleInterfaceManager(lu.tudor.ssi.kiss.tui.TangibleApplication, java.util.logging.Logger, java.util.Properties)}.
* @throws SecurityException
* Thrown when a security manager is present and a discrepancy in the class loaders is
* detected or it denies access to the field.
* @throws NoSuchFieldException
* Thrown when the fields that this test wants to access do not exist.
* @throws IllegalAccessException
* Thrown when access to the field is not permitted.
* @throws IllegalArgumentException
* If the provided instance cannot give access to the field.
*/
@Test
public void testTuioConcreteAdapter() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
assertThat(tuiAdapter, is(notNullValue()));
Field interfaceManager =TuioConcreteAdapter.class.getSuperclass().getDeclaredField("interfaceManager");
Field client = TuioConcreteAdapter.class.getDeclaredField("client");
Field objectManager = TuioConcreteAdapter.class.getDeclaredField("objectManager");
interfaceManager.setAccessible(true);
assertThat(interfaceManager.get(tuiAdapter), is(not(nullValue())));
client.setAccessible(true);
assertThat(client.get(tuiAdapter), is(not(nullValue())));
/** check if object manager is null (because instantiate client side */
objectManager.setAccessible(true);
assertThat(objectManager.get(tuiAdapter), is(nullValue()));
}
/**
* Class implementing the abstract {@link TangibleApplication} for test purposes.
* @author Eric TOBIAS [eric.tobias@tudor.lu]
* @since 13 Mar 2014
* @version 1
*/
public class TestTangibleApplication extends TangibleApplication
{
/**
* Constructor initialising several basic properties.
* @param newPropertiesFileURI
* The URI of the properties file to load.
*/
protected TestTangibleApplication(String newPropertiesFileURI)
{
super(newPropertiesFileURI);
}
}
/**
* Class implementing the abstract {@link TangibleObjectManager} for test purposes.
* @author Eric TOBIAS [eric.tobias@tudor.lu]
* @since 13 Mar 2014
* @version 1
*/
public class TestTangibleObjectManager extends TangibleObjectManager
{
/**
* Constructor initialising several fields and setting up the list of managed tangibles.
* @param applicationContext
* The {@link TangibleApplication} hosting this manager.
* @param applicationLogger
* The {@link Logger} to use for all logging purposes.
* @param properties
* The properties instance from which to load the default values from.
*/
@NonNullByDefault
public TestTangibleObjectManager(
TangibleApplication applicationContext,
Logger applicationLogger, Properties properties)
{
super(applicationContext, applicationLogger, properties);
}
/**
* {@inheritDoc}
*/
@Override
public void defineWidgets() throws BuildException
{
throw new BuildException("No widgets to build in this mock!");
}
}
@Test
public void testGetObjectManager()
{
/** check if object manager is null (because instantiate client side */
assertThat(tuiAdapter.getObjectManager(), is(nullValue()));
}
@Test
public void testSetObjectManager()
{
tuiAdapter.setObjectManager(application.getObjectManager());
assertEquals(application.getObjectManager(), tuiAdapter.getObjectManager());
}
@Test
public void testGetActiveCursors()
{
assertThat(tuiAdapter.getActiveCursors(), is(not(nullValue())));
}
@Test
public void testGetActiveObjects()
{
assertThat(tuiAdapter.getActiveObjects(), is(not(nullValue())));
}
@Test
public void testGetCursor()
{
/** Catch if I try to convert a null cursor (see precondition method) */
try {
/** No object currently added*/
assertThat(tuiAdapter.getCursor(1096), is(not(nullValue())));
} catch(IllegalArgumentException e) {
}
}
@Test
public void testGetObject()
{
/** Catch if I try to convert a null object (see precondition method) */
try {
/** No object currently added*/
assertThat(tuiAdapter.getObject(23), is(not(nullValue())));
} catch(IllegalArgumentException e) {
}
}
@Test
public void testConvertTuioCursorToTangibleObject() {
TuioCursor tuioCursor = new TuioCursor(1, 3, 10f, 11f);
Method convertTuioCursor = null;
try