Fix polar tests and sensor strings.

This commit is contained in:
Sandor Dornbush
2011-07-05 15:19:21 -07:00
parent 6823b08651
commit e6151b3b71
5 changed files with 47 additions and 32 deletions
+1 -6
View File
@@ -410,10 +410,5 @@ limitations under the License.
<string name="sending">S\'està enviant</string>
<!-- Sensor Type Options -->
<string name="no_sensor_option">NONE</string>
<string name="ant_sensor_option">ANT+ Sensors</string>
<string name="ant_bridge_sensor_option">SRM ANT+ Bridge</string>
<string name="polar_bt_sensor_option">Polar Bluetooth</string>
<string name="zephyr_bt_sensor_option">Zephyr Bluetooth</string>
<string name="no_sensor_option">Cap</string>
</resources>
+3 -6
View File
@@ -129,10 +129,7 @@ limitations under the License.
-->
<!-- Sensor Type Options -->
<string name="no_sensor_option">NONE</string>
<string name="ant_sensor_option">ANT+ Sensors</string>
<string name="ant_bridge_sensor_option">SRM ANT+ Bridge</string>
<string name="polar_bt_sensor_option">Polar Bluetooth</string>
<string name="zephyr_bt_sensor_option">Zephyr Bluetooth</string>
<string name="no_sensor_option">Ninguna</string>
<string name="ant_sensor_option">ANT+ Sensores</string>
<string name="ant_bridge_sensor_option">SRM ANT+ Puente</string>
</resources>
-2
View File
@@ -467,8 +467,6 @@ limitations under the License.
<string name="no_sensor_option">なし</string>
<string name="ant_sensor_option">ANT+ センサー</string>
<string name="ant_bridge_sensor_option">SRM ANT+ ブリッジ</string>
<string name="polar_bt_sensor_option">Polar Bluetooth</string>
<string name="zephyr_bt_sensor_option">Zephyr Bluetooth</string>
<!-- Manifest description (not seen inside the app) -->
<string name="notification_permission_label">トラック記録通知受信</string>
-2
View File
@@ -494,8 +494,6 @@ limitations under the License.
<string name="no_sensor_option">Нет</string>
<string name="ant_sensor_option">ANT+ Датчик</string>
<string name="ant_bridge_sensor_option">SRM ANT+ Bridge</string>
<string name="polar_bt_sensor_option">Polar Bluetooth</string>
<string name="zephyr_bt_sensor_option">Zephyr Bluetooth</string>
<!-- Manifest description (not seen inside the app) -->
<string name="notification_permission_label">получать уведомления о записи трека</string>
@@ -1,5 +1,7 @@
package com.google.android.apps.mytracks.services.sensors;
import java.util.Arrays;
import com.google.android.apps.mytracks.content.Sensor;
import junit.framework.TestCase;
@@ -7,26 +9,40 @@ import junit.framework.TestCase;
public class PolarMessageParserTest extends TestCase {
PolarMessageParser parser = new PolarMessageParser();
// A complete and valid Polar HxM packet
// FE08F701D1001104FE08F702D1001104
private final byte[] originalBuf =
{(byte) 0xFE, 0x08, (byte) 0xF7, 0x01, (byte) 0xD1, 0x00, 0x11, 0x04, (byte) 0xFE, 0x08,
(byte) 0xF7, 0x02, (byte) 0xD1, 0x00, 0x11, 0x04};
private byte[] buf;
public void setUp() {
buf = Arrays.copyOf(originalBuf, originalBuf.length);
}
public void testIsValid() {
// A complete and valid Polar HxM packet
// FE08F701D1001104FE08F702D1001104
byte[] buf = { 0xFE,0x08,0xF7,0x01,0xD1,0x00,0x11,0x04,0xFE,0x08,0xF7,0x02,0xD1,0x00,0x11,0x04 };
buf[0] = 0x03; // Invalidate header
assertTrue(parser.isValid(buf));
}
public void testIsValid_invalidHeader() {
// Invalidate header.
buf[0] = 0x03;
assertFalse(parser.isValid(buf));
buf[0] = 0xFE; // Good header
buf[2] = 0x03; // Invalidate checkbyte
}
public void testIsValid_invalidCheckbyte() {
// Invalidate checkbyte.
buf[2] = 0x03;
assertFalse(parser.isValid(buf));
buf[2] = 0xF7; // Good checkbyte
buf[3] = 0x11; // Invalidate sequence
}
public void testIsValid_invalidSequence() {
// Invalidate sequence.
buf[3] = 0x11;
assertFalse(parser.isValid(buf));
}
public void testParseBuffer() {
byte[] buf = { 0xFE,0x08,0xF7,0x01,0xD1,0x00,0x11,0x04,0xFE,0x08,0xF7,0x02,0xD1,0x00,0x11,0x04 };
buf[5] = 70;
Sensor.SensorDataSet sds = parser.parseBuffer(buf);
assertTrue(sds.hasHeartRate());
@@ -34,10 +50,21 @@ public class PolarMessageParserTest extends TestCase {
assertEquals(70, sds.getHeartRate().getValue());
}
public void testFindNextAlignment() {
byte[] buf = { 0x0E,0x08,0xF7,0x01,0xD1,0x00,0x11,0x04,0x0E,0x08,0xF7,0x02,0xD1,0x00,0x11,0x04 };
public void testFindNextAlignment_offset() {
// The first 4 bytes are garbage
buf = new byte[originalBuf.length + 4];
buf[0] = 4;
buf[1] = 2;
buf[2] = 4;
buf[3] = 2;
// Then the valid message.
System.arraycopy(originalBuf, 0, buf, 4, originalBuf.length);
assertEquals(4, parser.findNextAlignment(buf));
}
public void testFindNextAlignment_invalid() {
buf[0] = 0;
assertEquals(-1, parser.findNextAlignment(buf));
buf[8] = 0xFE;
assertEquals(8, parser.findNextAlignment(buf));
}
}