1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Test case for the callbacks

This commit is contained in:
James Cotton 2011-03-07 04:56:14 -06:00
parent 97b5f758a0
commit 1ffe0691f5

View File

@ -0,0 +1,95 @@
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;
import android.database.Observable;
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");
}
}