1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-10 18:24:11 +01:00
LibrePilot/androidgcs/tests/org/openpilot/uavtalk/DataObjectTest.java
2012-08-06 01:26:10 -05:00

94 lines
2.0 KiB
Java

package org.openpilot.uavtalk;
import static org.junit.Assert.*;
import java.nio.ByteBuffer;
import java.util.Observer;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openpilot.uavtalk.uavobjects.ActuatorCommand;
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
public class DataObjectTest {
boolean succeed = false;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void testUpdatedObserver() {
succeed = false;
UAVObject obj = new ActuatorCommand();
obj.addUpdatedObserver( new Observer() {
public void update(java.util.Observable observable, Object data) {
System.out.println("Updated: " + data.toString());
succeed = true;
}
});
obj.updated();
if(!succeed)
fail("No callback");
System.out.println("Done");
}
@Test
public void testUpdatedViaObjMngr() {
succeed = false;
UAVObjectManager objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
UAVObject obj = objMngr.getObject("FlightTelemetryStats");
obj.addUpdatedObserver( new Observer() {
public void update(java.util.Observable observable, Object data) {
System.out.println("Updated: " + data.toString());
succeed = true;
}
});
objMngr.getObject("FlightTelemetryStats").updated();
if(!succeed)
fail("No callback");
System.out.println("Done");
}
@Test
public void testUnpackedViaObjMngr() {
succeed = false;
UAVObjectManager objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
UAVObject obj = objMngr.getObject("FlightTelemetryStats");
obj.addUnpackedObserver( new Observer() {
public void update(java.util.Observable observable, Object data) {
System.out.println("Updated: " + data.toString());
succeed = true;
}
});
ByteBuffer bbuf = ByteBuffer.allocate(obj.getNumBytes());
objMngr.getObject("FlightTelemetryStats").unpack(bbuf);
if(!succeed)
fail("No callback");
System.out.println("Done");
}
}