mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
Test case for the callbacks
This commit is contained in:
parent
97b5f758a0
commit
1ffe0691f5
95
androidgcs/tests/org/openpilot/uavtalk/DataObjectTest.java
Normal file
95
androidgcs/tests/org/openpilot/uavtalk/DataObjectTest.java
Normal 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");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user