forked from upstream-mirrors/OpenTracks
Adding more tests and other minor fixes.
This commit is contained in:
@@ -21,6 +21,9 @@
|
|||||||
<string name="settings_auto_start">Automatic start</string>
|
<string name="settings_auto_start">Automatic start</string>
|
||||||
<string name="settings_auto_start_summary_on">Automatically start inserting signal strength waypoints whenever My Tracks starts recording a track.</string>
|
<string name="settings_auto_start_summary_on">Automatically start inserting signal strength waypoints whenever My Tracks starts recording a track.</string>
|
||||||
<string name="settings_auto_start_summary_off">You will need to manually start signal sampling using the controls below.</string>
|
<string name="settings_auto_start_summary_off">You will need to manually start signal sampling using the controls below.</string>
|
||||||
|
<string name="settings_auto_stop">Automatic stop</string>
|
||||||
|
<string name="settings_auto_stop_summary_on">Automatically stop inserting signal strength waypoints whenever My Tracks stops recording a track.</string>
|
||||||
|
<string name="settings_auto_stop_summary_off">You will need to manually stop signal sampling using the controls below.</string>
|
||||||
<string name="settings_min_signal_sampling_period">Min. sampling period</string>
|
<string name="settings_min_signal_sampling_period">Min. sampling period</string>
|
||||||
<string name="settings_min_signal_sampling_period_summary">Minimum time between two recordings of the phone\'s signal strength</string>
|
<string name="settings_min_signal_sampling_period_summary">Minimum time between two recordings of the phone\'s signal strength</string>
|
||||||
|
|
||||||
@@ -44,6 +47,7 @@
|
|||||||
|
|
||||||
<!-- Non-translatable strings -->
|
<!-- Non-translatable strings -->
|
||||||
<string name="settings_auto_start_key">autoStartSampling</string>
|
<string name="settings_auto_start_key">autoStartSampling</string>
|
||||||
|
<string name="settings_auto_stop_key">autoStopSampling</string>
|
||||||
<string name="settings_min_signal_sampling_period_key">signalSamplingFrequency</string>
|
<string name="settings_min_signal_sampling_period_key">signalSamplingFrequency</string>
|
||||||
<string name="settings_control_start_key">startSamplingControl</string>
|
<string name="settings_control_start_key">startSamplingControl</string>
|
||||||
<string name="settings_control_stop_key">stopSamplingControl</string>
|
<string name="settings_control_stop_key">stopSamplingControl</string>
|
||||||
|
|||||||
@@ -21,6 +21,11 @@
|
|||||||
android:summaryOn="@string/settings_auto_start_summary_on"
|
android:summaryOn="@string/settings_auto_start_summary_on"
|
||||||
android:summaryOff="@string/settings_auto_start_summary_off"
|
android:summaryOff="@string/settings_auto_start_summary_off"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
<CheckBoxPreference android:key="@string/settings_auto_stop_key"
|
||||||
|
android:title="@string/settings_auto_stop"
|
||||||
|
android:summaryOn="@string/settings_auto_stop_summary_on"
|
||||||
|
android:summaryOff="@string/settings_auto_stop_summary_off"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="@string/settings_min_signal_sampling_period_key"
|
android:key="@string/settings_min_signal_sampling_period_key"
|
||||||
|
|||||||
+14
-6
@@ -32,19 +32,27 @@ public class RecordingStateReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context ctx, Intent intent) {
|
public void onReceive(Context ctx, Intent intent) {
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
boolean autoStart = preferences.getBoolean(
|
|
||||||
ctx.getString(R.string.settings_auto_start_key), false);
|
|
||||||
if (!autoStart) {
|
|
||||||
Log.d(TAG, "Not auto-starting signal sampling");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (ctx.getString(R.string.track_started_broadcast_action).equals(action) ||
|
if (ctx.getString(R.string.track_started_broadcast_action).equals(action) ||
|
||||||
ctx.getString(R.string.track_resumed_broadcast_action).equals(action)) {
|
ctx.getString(R.string.track_resumed_broadcast_action).equals(action)) {
|
||||||
|
boolean autoStart = preferences.getBoolean(
|
||||||
|
ctx.getString(R.string.settings_auto_start_key), false);
|
||||||
|
if (!autoStart) {
|
||||||
|
Log.d(TAG, "Not auto-starting signal sampling");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
startService(ctx);
|
startService(ctx);
|
||||||
} else if (ctx.getString(R.string.track_stopped_broadcast_action).equals(action) ||
|
} else if (ctx.getString(R.string.track_stopped_broadcast_action).equals(action) ||
|
||||||
ctx.getString(R.string.track_paused_broadcast_action).equals(action)) {
|
ctx.getString(R.string.track_paused_broadcast_action).equals(action)) {
|
||||||
|
boolean autoStop = preferences.getBoolean(
|
||||||
|
ctx.getString(R.string.settings_auto_stop_key), true);
|
||||||
|
if (!autoStop) {
|
||||||
|
Log.d(TAG, "Not auto-stopping signal sampling");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
stopService(ctx);
|
stopService(ctx);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Unknown action received: " + action);
|
Log.e(TAG, "Unknown action received: " + action);
|
||||||
|
|||||||
+3
-4
@@ -58,10 +58,9 @@ public class SignalStrengthService extends Service
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
mytracksServiceComponent =
|
mytracksServiceComponent = new ComponentName(
|
||||||
new ComponentName(
|
getString(R.string.mytracks_service_package),
|
||||||
getString(R.string.mytracks_service_package),
|
getString(R.string.mytracks_service_class));
|
||||||
getString(R.string.mytracks_service_class));
|
|
||||||
preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
signalListenerFactory = new SignalStrengthListenerFactory();
|
signalListenerFactory = new SignalStrengthListenerFactory();
|
||||||
}
|
}
|
||||||
|
|||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 Google Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.apps.mytracks.signalstrength.test;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.signalstrength.R;
|
||||||
|
import com.google.android.apps.mytracks.signalstrength.RecordingStateReceiver;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
import android.test.RenamingDelegatingContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link RecordingStateReceiver}.
|
||||||
|
*
|
||||||
|
* @author Rodrigo Damazio
|
||||||
|
*/
|
||||||
|
public class RecordingStateReceiverTest extends AndroidTestCase {
|
||||||
|
|
||||||
|
private RecordingStateReceiver receiver;
|
||||||
|
private RenamingDelegatingContext context;
|
||||||
|
private SharedPreferences preferences;
|
||||||
|
private int serviceStopCalls;
|
||||||
|
private int serviceStartCalls;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
context = new RenamingDelegatingContext(getContext(), "test.");
|
||||||
|
setContext(context);
|
||||||
|
|
||||||
|
receiver = new RecordingStateReceiver() {
|
||||||
|
@Override
|
||||||
|
protected void stopService(Context ctx) {
|
||||||
|
serviceStopCalls++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void startService(Context ctx) {
|
||||||
|
serviceStartCalls++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
preferences
|
||||||
|
.edit()
|
||||||
|
.putBoolean(context.getString(R.string.settings_auto_start_key), true)
|
||||||
|
.putBoolean(context.getString(R.string.settings_auto_stop_key), true)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOnReceive_start() {
|
||||||
|
receiver.onReceive(context,
|
||||||
|
new Intent(context.getString(R.string.track_started_broadcast_action)));
|
||||||
|
assertServiceCalls(1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOnReceive_resume() {
|
||||||
|
receiver.onReceive(context,
|
||||||
|
new Intent(context.getString(R.string.track_resumed_broadcast_action)));
|
||||||
|
assertServiceCalls(1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOnReceive_stop() {
|
||||||
|
receiver.onReceive(context,
|
||||||
|
new Intent(context.getString(R.string.track_stopped_broadcast_action)));
|
||||||
|
assertServiceCalls(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOnReceive_pause() {
|
||||||
|
receiver.onReceive(context,
|
||||||
|
new Intent(context.getString(R.string.track_paused_broadcast_action)));
|
||||||
|
assertServiceCalls(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOnReceive_noAutoStart() {
|
||||||
|
preferences
|
||||||
|
.edit()
|
||||||
|
.putBoolean(context.getString(R.string.settings_auto_start_key), false)
|
||||||
|
.commit();
|
||||||
|
receiver.onReceive(context,
|
||||||
|
new Intent(context.getString(R.string.track_started_broadcast_action)));
|
||||||
|
assertServiceCalls(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOnReceive_noAutoStop() {
|
||||||
|
preferences
|
||||||
|
.edit()
|
||||||
|
.putBoolean(context.getString(R.string.settings_auto_stop_key), false)
|
||||||
|
.commit();
|
||||||
|
receiver.onReceive(context,
|
||||||
|
new Intent(context.getString(R.string.track_stopped_broadcast_action)));
|
||||||
|
assertServiceCalls(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOnReceive_other() {
|
||||||
|
receiver.onReceive(context, new Intent("bla"));
|
||||||
|
assertServiceCalls(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertServiceCalls(int startCalls, int stopCalls) {
|
||||||
|
assertEquals(startCalls, serviceStartCalls);
|
||||||
|
assertEquals(stopCalls, serviceStopCalls);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user