mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-825 Add first pass test project. Contains basic tests for OPTelemetryService
This commit is contained in:
parent
99a3708586
commit
13cb5b8fbb
9
androidgcstests/.classpath
Normal file
9
androidgcstests/.classpath
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/androidgcs"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
33
androidgcstests/.project
Normal file
33
androidgcstests/.project
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>androidgcstests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
19
androidgcstests/AndroidManifest.xml
Normal file
19
androidgcstests/AndroidManifest.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.openpilot.androidgcs.test"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" />
|
||||
|
||||
<instrumentation
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
android:targetPackage="org.openpilot.androidgcs" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
20
androidgcstests/proguard-project.txt
Normal file
20
androidgcstests/proguard-project.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
14
androidgcstests/project.properties
Normal file
14
androidgcstests/project.properties
Normal file
@ -0,0 +1,14 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-14
|
BIN
androidgcstests/res/drawable-hdpi/ic_launcher.png
Normal file
BIN
androidgcstests/res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
androidgcstests/res/drawable-ldpi/ic_launcher.png
Normal file
BIN
androidgcstests/res/drawable-ldpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
androidgcstests/res/drawable-mdpi/ic_launcher.png
Normal file
BIN
androidgcstests/res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
BIN
androidgcstests/res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
androidgcstests/res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
6
androidgcstests/res/values/strings.xml
Normal file
6
androidgcstests/res/values/strings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">AndroidGCSTestTest</string>
|
||||
|
||||
</resources>
|
@ -0,0 +1,181 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file OPTelemetryServiceTests.java
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
|
||||
* @brief Tests for the OPTelemetryService class
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
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;
|
||||
import org.openpilot.androidgcs.telemetry.OPTelemetryService;
|
||||
import org.openpilot.androidgcs.telemetry.OPTelemetryService.LocalBinder;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.test.ServiceTestCase;
|
||||
import android.test.mock.MockApplication;
|
||||
import android.test.mock.MockContext;
|
||||
|
||||
public class OPTelemetryServiceTests extends
|
||||
ServiceTestCase<OPTelemetryService> {
|
||||
|
||||
private Object _syncTelemetryTaskStarted = new Object();
|
||||
private Object _syncTelemetryConnected = new Object();
|
||||
private BroadcastReceiver _connectBroadcastReceiver;
|
||||
|
||||
public class MockAndroidGCSApplication extends MockApplication {
|
||||
|
||||
}
|
||||
|
||||
class MockAndroidGCSContext extends MockContext {
|
||||
|
||||
}
|
||||
|
||||
public OPTelemetryServiceTests() {
|
||||
this(OPTelemetryService.class);
|
||||
}
|
||||
|
||||
public OPTelemetryServiceTests(Class<OPTelemetryService> serviceClass) {
|
||||
super(serviceClass);
|
||||
_connectBroadcastReceiver = new BroadcastReceiver(){
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_CONNECTED)) {
|
||||
if(_syncTelemetryConnected != null){
|
||||
synchronized (_syncTelemetryConnected) {
|
||||
_syncTelemetryConnected.notify();
|
||||
}
|
||||
}
|
||||
}else if(intent.getAction().equals(OPTelemetryService.INTENT_ACTION_TELEMETRYTASK_STARTED)) {
|
||||
// Not looked into why _syncTelemetryTaskStarted could possibly be null
|
||||
// here but sometimes it is...
|
||||
if(_syncTelemetryTaskStarted != null){
|
||||
synchronized (_syncTelemetryTaskStarted) {
|
||||
_syncTelemetryTaskStarted.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addCategory(OPTelemetryService.INTENT_CATEGORY_GCS);
|
||||
filter.addAction(OPTelemetryService.INTENT_ACTION_CONNECTED);
|
||||
filter.addAction(OPTelemetryService.INTENT_ACTION_TELEMETRYTASK_STARTED);
|
||||
|
||||
getContext().registerReceiver(_connectBroadcastReceiver, filter);
|
||||
|
||||
// setApplication(new MockAndroidGCSApplication());
|
||||
// setContext(new MockAndroidGCSContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
// getContext().unregisterReceiver(_connectBroadcastReceiver);
|
||||
}
|
||||
|
||||
public void testLifecycleSingleStart(){
|
||||
bindService(new Intent(getContext(),
|
||||
org.openpilot.androidgcs.telemetry.OPTelemetryService.class));
|
||||
|
||||
assertEquals(1, OPTelemetryService.getNumStartupRequests());
|
||||
|
||||
shutdownService();
|
||||
|
||||
assertEquals(0, OPTelemetryService.getNumStartupRequests());
|
||||
}
|
||||
|
||||
public void testLifecycleMultiStart(){
|
||||
bindService(new Intent(getContext(),
|
||||
org.openpilot.androidgcs.telemetry.OPTelemetryService.class));
|
||||
bindService(new Intent(getContext(),
|
||||
org.openpilot.androidgcs.telemetry.OPTelemetryService.class));
|
||||
|
||||
assertEquals(1, OPTelemetryService.getNumStartupRequests());
|
||||
|
||||
shutdownService();
|
||||
|
||||
assertEquals(0, OPTelemetryService.getNumStartupRequests());
|
||||
}
|
||||
|
||||
public void testStartBluetoothTelemetryTask(){
|
||||
LocalBinder binder = startTelemetryTask(Integer.valueOf(2));
|
||||
|
||||
assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof BluetoothUAVTalk);
|
||||
}
|
||||
|
||||
public void testStartBluetoothConnection() throws InterruptedException{
|
||||
LocalBinder binder = startTelemetryTask(Integer.valueOf(2));
|
||||
|
||||
synchronized (_syncTelemetryConnected) {
|
||||
_syncTelemetryConnected.wait(2000);
|
||||
}
|
||||
|
||||
assertTrue("Failed to connect to telemetry service", binder.isConnected());
|
||||
|
||||
assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof BluetoothUAVTalk);
|
||||
}
|
||||
|
||||
public void testStartTCPTelemetryTask(){
|
||||
LocalBinder binder = startTelemetryTask(Integer.valueOf(3));
|
||||
|
||||
assertTrue("Started wrong telemetry service type", binder.getTelemetryTask(0) instanceof TcpUAVTalk);
|
||||
}
|
||||
|
||||
public void testStartUSBTelemetryTask(){
|
||||
LocalBinder binder = startTelemetryTask(Integer.valueOf(4));
|
||||
|
||||
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));
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString("connection_type", telemetryType.toString());
|
||||
editor.apply();
|
||||
|
||||
binder.openConnection();
|
||||
synchronized (_syncTelemetryTaskStarted) {
|
||||
try {
|
||||
_syncTelemetryTaskStarted.wait(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return binder;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user