From 1d96dfd30e42456b3ebb076b8badcaed34787a74 Mon Sep 17 00:00:00 2001 From: David Willis Date: Sun, 10 Feb 2013 01:18:24 +0000 Subject: [PATCH] OP-825 Add connection tests for TCP and USB --- .../OPTelemetryServiceTests.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/androidgcstests/src/org/openpilot/androidgcs/test/telemetryservice/OPTelemetryServiceTests.java b/androidgcstests/src/org/openpilot/androidgcs/test/telemetryservice/OPTelemetryServiceTests.java index 7513b20b0..bc3149543 100644 --- a/androidgcstests/src/org/openpilot/androidgcs/test/telemetryservice/OPTelemetryServiceTests.java +++ b/androidgcstests/src/org/openpilot/androidgcs/test/telemetryservice/OPTelemetryServiceTests.java @@ -23,7 +23,6 @@ */ package org.openpilot.androidgcs.test.telemetryservice; -import org.junit.Ignore; import org.openpilot.androidgcs.telemetry.HidUAVTalk; import org.openpilot.androidgcs.telemetry.TcpUAVTalk; import org.openpilot.androidgcs.telemetry.BluetoothUAVTalk; @@ -42,6 +41,9 @@ import android.test.mock.MockContext; public class OPTelemetryServiceTests extends ServiceTestCase { + private static final int PREF_BLUETOOTH_CONN = 2; + private static final int PREF_TCP_CONN = 3; + private static final int PREF_USB_CONN = 4; private Object _syncTelemetryTaskStarted = new Object(); private Object _syncTelemetryConnected = new Object(); private BroadcastReceiver _connectBroadcastReceiver; @@ -130,13 +132,13 @@ public class OPTelemetryServiceTests extends } public void testStartBluetoothTelemetryTask(){ - LocalBinder binder = startTelemetryTask(Integer.valueOf(2)); + LocalBinder binder = startTelemetryTask(Integer.valueOf(PREF_BLUETOOTH_CONN)); assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof BluetoothUAVTalk); } public void testStartBluetoothConnection() throws InterruptedException{ - LocalBinder binder = startTelemetryTask(Integer.valueOf(2)); + LocalBinder binder = startTelemetryTask(Integer.valueOf(PREF_BLUETOOTH_CONN)); synchronized (_syncTelemetryConnected) { _syncTelemetryConnected.wait(2000); @@ -148,17 +150,41 @@ public class OPTelemetryServiceTests extends } public void testStartTCPTelemetryTask(){ - LocalBinder binder = startTelemetryTask(Integer.valueOf(3)); + LocalBinder binder = startTelemetryTask(Integer.valueOf(PREF_TCP_CONN)); + + assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof TcpUAVTalk); + } + + public void testStartTCPConnection() throws InterruptedException{ + LocalBinder binder = startTelemetryTask(Integer.valueOf(PREF_TCP_CONN)); + + synchronized (_syncTelemetryConnected) { + _syncTelemetryConnected.wait(2000); + } + + assertTrue("Failed to connect to telemetry service", binder.isConnected()); assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof TcpUAVTalk); } public void testStartUSBTelemetryTask(){ - LocalBinder binder = startTelemetryTask(Integer.valueOf(4)); + LocalBinder binder = startTelemetryTask(Integer.valueOf(PREF_USB_CONN)); assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof HidUAVTalk); } + public void testStartUSBConnection() throws InterruptedException{ + LocalBinder binder = startTelemetryTask(Integer.valueOf(PREF_USB_CONN)); + + synchronized (_syncTelemetryConnected) { + _syncTelemetryConnected.wait(2000); + } + + assertTrue("Failed to connect to telemetry service", binder.isConnected()); + + assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof HidUAVTalk); + } + private LocalBinder startTelemetryTask(Integer telemetryType) { LocalBinder binder = (LocalBinder) bindService(new Intent(getContext(), org.openpilot.androidgcs.telemetry.OPTelemetryService.class));