1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

AndroidGCS: Remove the unit tests since they break the dynamic loading of UAVObjects

This commit is contained in:
James Cotton 2012-10-05 21:55:29 -05:00
parent df6d7eb11d
commit 80197f830c
7 changed files with 0 additions and 461 deletions

View File

@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>

View File

@ -1,93 +0,0 @@
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");
}
}

View File

@ -1,121 +0,0 @@
package org.openpilot.uavtalk;
import static org.junit.Assert.*;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openpilot.uavtalk.UAVObjectField;
import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.uavobjects.*;
public class FieldTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void testPackUint16() {
// Need an object initialized to the field to provide metadata
UAVObject obj = null;
try {
obj = new ActuatorCommand();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UAVObjectField field = new UAVObjectField("TestField", "No Units", UAVObjectField.FieldType.UINT16, 3, null);
field.initialize(obj);
field.setValue(3,0);
field.setValue(-50,1);
field.setValue(5003585,2);
ByteBuffer bbuf = ByteBuffer.allocate(field.getNumBytes());
try {
field.pack(bbuf);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("Buffer size incorrect");
}
// Expect data to come out as little endian
byte[] expected = {3,0,0,0,(byte) 0xff,(byte) 0xff};
for(int i = 0; i < expected.length && i < bbuf.array().length; i++) {
System.out.println("Expected: " + expected[i] + " (" + i + ")");
System.out.println("Received: " + bbuf.array()[i] + " (" + i + ")");
assertEquals(bbuf.array()[i],expected[i]);
}
}
@Test
public void testUnpackUint16() {
// Need an object initialized to the field to provide metadata
UAVObject obj = null;
obj = new ActuatorCommand();
UAVObjectField field = new UAVObjectField("TestField", "No Units", UAVObjectField.FieldType.UINT16, 3, null);
field.initialize(obj);
ByteBuffer bbuf = ByteBuffer.allocate(field.getNumBytes());
byte[] expected = {3,0,0,0,(byte) 0xff,(byte) 0xff};
bbuf.put(expected);
bbuf.position(0);
field.unpack(bbuf);
assertEquals(field.getValue(0), 3);
assertEquals(field.getValue(1), 0);
assertEquals(field.getValue(2), 65535);
}
@Test
public void testEnumSetGetValue() {
List<String> options = new ArrayList<String>();
options.add("Opt1");
options.add("Opt2");
options.add("Opt3");
// Need an object initialized to the field to provide metadata
UAVObject obj = null;
try {
obj = new ActuatorCommand();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UAVObjectField field = new UAVObjectField("TestField", "No Units", UAVObjectField.FieldType.ENUM, 3, options);
field.initialize(obj);
field.setValue("Opt1",0);
field.setValue("Opt2",1);
field.setValue("Opt3",2);
assertEquals(field.getValue(0), "Opt1");
assertEquals(field.getValue(1), "Opt2");
assertEquals(field.getValue(2), "Opt3");
}
@Test
public void testUint16SetGetValue() {
// Need an object initialized to the field to provide metadata
UAVObject obj = null;
try {
obj = new ActuatorCommand();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UAVObjectField field = new UAVObjectField("TestField", "No Units", UAVObjectField.FieldType.UINT16, 3, null);
field.initialize(obj);
field.setValue(3,0);
field.setValue(-50,1);
field.setValue(5003585,2);
assertEquals(field.getValue(0), 3);
assertEquals(field.getValue(1), 0);
assertEquals(field.getValue(2), 65535);
}
}

View File

@ -1,20 +0,0 @@
package org.openpilot.uavtalk;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
public class ObjMngrTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void testGetObjects() {
UAVObjectManager objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
// System.out.println(objMngr.getObject("ActuatorSettings", 0));
}
}

View File

@ -1,34 +0,0 @@
package org.openpilot.uavtalk;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
public class SettingsTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void testGetDefaultMetadata() {
fail("Not yet implemented");
}
@Test
public void testSetDefaultFieldValues() {
fail("Not yet implemented");
}
@Test
public void testIsSettings() {
fail("Not yet implemented");
}
@Test
public void testGetField() {
fail("Not yet implemented");
}
}

View File

@ -1,133 +0,0 @@
package org.openpilot.uavtalk;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Observable;
import java.util.Observer;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
import org.openpilot.uavtalk.UAVTalk;
public class TalkTest {
static UAVObjectManager objMngr;
static final String IP_ADDRDESS = new String("127.0.0.1");
static final int PORT_NUM = 7777;
boolean succeed = false;
byte[] flightStatsConnected =
{0x3c,0x20,0x1d,0x00,
(byte) 0x5e,(byte) 0x26,(byte) 0x0c,(byte) 0x66,
0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,(byte) 0xAE};
@BeforeClass
public static void setUpBeforeClass() throws Exception {
objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
}
//@Test
public void testGetFlightStatus() {
Socket connection = null;
UAVTalk talk = null;
try{
InetAddress ip = InetAddress.getByName(IP_ADDRDESS);
connection = new Socket(ip, PORT_NUM);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't connect to test platform");
}
try {
talk = new UAVTalk(connection.getInputStream(), connection.getOutputStream(), objMngr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("Couldn't construct UAVTalk object");
}
Thread inputStream = talk.getInputProcessThread();
inputStream.start();
succeed = false;
UAVObject obj = objMngr.getObject("FlightTelemetryStats");
obj.addUpdatedObserver( new Observer() {
public void update(Observable observable, Object data) {
// TODO Auto-generated method stub
System.out.println("Updated: " + data.toString());
succeed = true;
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
}
if(!succeed)
fail("Never received a FlightTelemetryStats update");
}
@Test
public void testSendObjectRequest() throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(new byte[0], 0, 0);
ByteArrayOutputStream os = new ByteArrayOutputStream(100);
UAVTalk talk = new UAVTalk(is,os,objMngr);
UAVObject obj = objMngr.getObject("FlightTelemetryStats");
obj.getField("Status").setValue("Connected");
talk.sendObject(obj, false, false);
System.out.println("Size: " + os.size());
byte [] array = os.toByteArray();
for(int i = 0; i < array.length; i++) {
System.out.print("0x" + Integer.toHexString((int) array[i] & 0xff));
System.out.print("/0x" + Integer.toHexString((int) flightStatsConnected[i] & 0xff));
if(i != array.length-1)
System.out.print("\n");
}
System.out.print("\n");
for(int i = 0; i < array.length; i++)
assertEquals(os.toByteArray()[i], flightStatsConnected[i]);
}
@Test
public void testReceiveObject() throws InterruptedException {
ByteArrayInputStream is = new ByteArrayInputStream(flightStatsConnected, 0, flightStatsConnected.length);
ByteArrayOutputStream os = new ByteArrayOutputStream(100);
// Make the Status wrong initially
UAVObject obj = objMngr.getObject("FlightTelemetryStats");
obj.getField("Status").setValue("Disconnected");
// Test receiving from that stream
UAVTalk talk = new UAVTalk(is,os,objMngr);
Thread inputStream = talk.getInputProcessThread();
inputStream.start();
Thread.sleep(1000);
System.out.println("Should be FlightTelemetry Stats:");
System.out.println(objMngr.getObject("FlightTelemetryStats").toString());
assertEquals(obj.getField("Status").getValue(), new String("Connected"));
}
}

View File

@ -1,59 +0,0 @@
package org.openpilot.uavtalk;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import org.junit.Test;
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
import android.os.Looper;
public class TelemetryMonitorTest {
static UAVObjectManager objMngr;
static UAVTalk talk;
static final String IP_ADDRDESS = new String("127.0.0.1");
static final int PORT_NUM = 7777;
static Socket connection = null;
boolean succeed = false;
@Test
public void testTelemetry() throws Exception {
objMngr = new UAVObjectManager();
UAVObjectsInitialize.register(objMngr);
talk = null;
try{
InetAddress ip = InetAddress.getByName(IP_ADDRDESS);
connection = new Socket(ip, PORT_NUM);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't connect to test platform");
}
try {
talk = new UAVTalk(connection.getInputStream(), connection.getOutputStream(), objMngr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("Couldn't construct UAVTalk object");
}
Thread inputStream = talk.getInputProcessThread();
inputStream.start();
Looper.prepare();
Telemetry tel = new Telemetry(talk, objMngr, Looper.myLooper());
@SuppressWarnings("unused")
TelemetryMonitor mon = new TelemetryMonitor(objMngr,tel);
Thread.sleep(10000);
System.out.println("Done");
}
}