Commit 88322140 authored by mikecase's avatar mikecase Committed by Commit bot

Add initial test and build files for Robolectric unit test suites.

Robolectric allows us to run tests that use Android code in the host
JVM. This means faster and more stable tests since we don't have to
deal with a device. This CL has the build file changes to build the
unit test suite, and two example tests that have been converted to
run with Robolectric.

BUG=448030

Review URL: https://codereview.chromium.org/994283006

Cr-Commit-Position: refs/heads/master@{#322512}
parent 4c27bf72
......@@ -447,6 +447,19 @@ android_apk("chrome_shell_test_apk") {
android_manifest = "shell/javatests/AndroidManifest.xml"
}
# GYP: //chrome/chrome_tests.gypi:chrome_shell_unit_tests
java_binary("chrome_shell_unit_tests") {
testonly = true
java_files = [ "android/junit/src/org/chromium/chrome/browser/omaha/ResponseParserTest.java" ]
main_class = "org.chromium.testing.local.JunitTestMain"
deps = [
":chrome_java",
"//base:base_java",
"//base:base_java_test_support",
"//testing/android/junit:junit_test_support",
]
}
# GYP: //chrome/chrome_tests.gypi:chrome_sync_shell_test_apk
android_apk("chrome_sync_shell_test_apk") {
testonly = true
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.omaha;
import android.util.Xml;
import org.chromium.base.test.util.Feature;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.io.StringWriter;
/**
* Unit tests for the Omaha ResponseParser.
*/
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class ResponseParserTest {
// Note that the Omaha server appends "/" to the end of the URL codebase.
private static final String STRIPPED_URL =
"https://play.google.com/store/apps/details?id=com.google.android.apps.chrome";
private static final String URL = STRIPPED_URL + "/";
private static final String NEXT_VERSION = "1.2.3.4";
private static final String APP_STATUS_OK = "ok";
private static final String APP_STATUS_RESTRICTED = "restricted";
private static final String APP_STATUS_ERROR = "error-whatever-else";
private static final String UPDATE_STATUS_OK = "ok";
private static final String UPDATE_STATUS_NOUPDATE = "noupdate";
private static final String UPDATE_STATUS_ERROR = "error-osnotsupported";
private static final String UPDATE_STATUS_WTF = "omgwtfbbq";
/**
* Create XML for testing.
* @param xmlProtocol Version number of the protocol. Expected to be "3.0" for valid XML.
* @param elapsedSeconds Number of seconds since server midnight.
* @param appStatus Status to use for the <app> element.
* @param addInstall Whether or not to add an install event.
* @param addPing Whether or not to add a ping event.
* @param updateStatus Status to use for the <updatecheck> element.
* @return The completed XML.
*/
private static String createTestXML(String xmlProtocol, String elapsedSeconds,
String appStatus, boolean addInstall, boolean addPing, String updateStatus,
String updateUrl) {
StringWriter writer = new StringWriter();
try {
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(writer);
serializer.startDocument("UTF-8", true);
// Set up <response ...>
serializer.startTag(null, "response");
serializer.attribute(null, "server", "prod");
if (xmlProtocol != null) {
serializer.attribute(null, "protocol", xmlProtocol);
}
// Create <daystart> element.
if (elapsedSeconds != null) {
serializer.startTag(null, "daystart");
serializer.attribute(null, "elapsed_seconds", elapsedSeconds);
serializer.endTag(null, "daystart");
}
// Create <app> element with unused attribute.
serializer.startTag(null, "app");
serializer.attribute(null, "appid", "{APP_ID}");
serializer.attribute(null, "status", appStatus);
serializer.attribute(null, "unused", "attribute");
if (addInstall) {
serializer.startTag(null, "event");
serializer.attribute(null, "status", "ok");
serializer.endTag(null, "event");
}
if (addPing) {
serializer.startTag(null, "ping");
serializer.attribute(null, "status", "ok");
serializer.endTag(null, "ping");
}
if (updateStatus != null) {
serializer.startTag(null, "updatecheck");
serializer.attribute(null, "status", updateStatus);
if (UPDATE_STATUS_OK.equals(updateStatus)) {
createUpdateXML(serializer, updateUrl);
}
serializer.endTag(null, "updatecheck");
}
serializer.endTag(null, "app");
// Create extraneous tag.
serializer.startTag(null, "extraneous");
serializer.attribute(null, "useless", "yes");
serializer.endTag(null, "extraneous");
serializer.endTag(null, "response");
serializer.endDocument();
} catch (IOException e) {
Assert.fail("Caught an IOException creating the XML: " + e);
} catch (IllegalArgumentException e) {
Assert.fail("Caught an IllegalArgumentException creating the XML: " + e);
} catch (IllegalStateException e) {
Assert.fail("Caught an IllegalStateException creating the XML: " + e);
}
return writer.toString();
}
private static void createUpdateXML(XmlSerializer serializer, String updateUrl)
throws IOException {
// End result should look something like:
// <updatecheck status="ok">
// <urls>
// <url codebase="URL" />
// </urls>
// <manifest garbage="attribute" version="NEXT_VERSION">
// <packages>
// <package hash="0" name="dummy.apk" required="true" size="0" />
// </packages>
// <actions>
// <action event="install" run="dummy.apk" />
// <action event="postinstall" />
// </actions>
// </manifest>
// <better be="ignored" />
//</updatecheck>
// Create <urls> and its descendants.
serializer.startTag(null, "urls");
if (updateUrl != null) {
serializer.startTag(null, "url");
serializer.attribute(null, "codebase", updateUrl);
serializer.endTag(null, "url");
}
serializer.endTag(null, "urls");
// Create <manifest> and its descendants.
serializer.startTag(null, "manifest");
serializer.attribute(null, "garbage", "attribute");
serializer.attribute(null, "version", NEXT_VERSION);
// Create <packages> and its children.
serializer.startTag(null, "packages");
serializer.startTag(null, "package");
serializer.attribute(null, "hash", "0");
serializer.attribute(null, "name", "dummy.apk");
serializer.attribute(null, "required", "true");
serializer.attribute(null, "size", "0");
serializer.endTag(null, "package");
serializer.endTag(null, "packages");
// Create <actions> and its children.
serializer.startTag(null, "actions");
serializer.startTag(null, "action");
serializer.attribute(null, "event", "install");
serializer.attribute(null, "run", "dummy.apk");
serializer.endTag(null, "action");
serializer.startTag(null, "action");
serializer.attribute(null, "event", "postinstall");
serializer.endTag(null, "action");
serializer.endTag(null, "actions");
serializer.endTag(null, "manifest");
// Create a dummy element for testing to make sure it's ignored.
serializer.startTag(null, "dummy");
serializer.attribute(null, "hopefully", "ignored");
serializer.endTag(null, "dummy");
}
/**
* Runs a test that is expected to pass.
* @param appStatus Status to use for the <app> element.
* @param addInstall Whether or not to add an install event.
* @param addPing Whether or not to add a ping.
* @param updateStatus Status to use for the <updatecheck> element.
* @throws RequestFailureException Thrown if the test fails.
*/
private static void runSuccessTest(String appStatus, boolean addInstall, boolean addPing,
String updateStatus) throws RequestFailureException {
String xml =
createTestXML("3.0", "12345", appStatus, addInstall, addPing, updateStatus, URL);
ResponseParser parser =
new ResponseParser(true, "{APP_ID}", addInstall, addPing, updateStatus != null);
parser.parseResponse(xml);
Assert.assertEquals("elapsed_seconds doesn't match.", 12345, parser.getDaystartSeconds());
Assert.assertEquals("<app> status doesn't match.", appStatus, parser.getAppStatus());
Assert.assertEquals(
"<updatecheck> status doesn't match.", updateStatus, parser.getUpdateStatus());
if (UPDATE_STATUS_OK.equals(updateStatus)) {
Assert.assertEquals(
"Version number doesn't match.", "1.2.3.4", parser.getNewVersion());
Assert.assertEquals(
"Market URL doesn't match.", STRIPPED_URL, parser.getURL());
} else {
Assert.assertEquals(
"Version number doesn't match.", null, parser.getNewVersion());
Assert.assertEquals(
"Market URL doesn't match.", null, parser.getURL());
}
}
/**
* Runs a test that is expected to fail in a particular way.
* @param xml XML to parse.
* @param expectedErrorCode Expected error code.
* @param expectInstall Whether or not the parser should expect an install event.
* @param expectPing Whether or not the parser should expect a ping element.
* @param expectUpdate Whether or not the parser should expect an update check.
*/
private static void runFailureTest(String xml, int expectedErrorCode,
boolean expectInstall, boolean expectPing, boolean expectUpdate) {
ResponseParser parser =
new ResponseParser(true, "{APP_ID}", expectInstall, expectPing, expectUpdate);
try {
parser.parseResponse(xml);
} catch (RequestFailureException e) {
Assert.assertEquals("Incorrect error code received.", expectedErrorCode, e.errorCode);
return;
}
Assert.fail("Failed to throw RequestFailureException for bad XML.");
}
@Test
@Feature({"Omaha"})
public void testValidAllTypes() throws RequestFailureException {
runSuccessTest(APP_STATUS_OK, true, true, UPDATE_STATUS_OK);
}
@Test
@Feature({"Omaha"})
public void testValidNoInstall() throws RequestFailureException {
runSuccessTest(APP_STATUS_OK, false, true, UPDATE_STATUS_OK);
}
@Test
@Feature({"Omaha"})
public void testValidNoPing() throws RequestFailureException {
runSuccessTest(APP_STATUS_OK, true, false, UPDATE_STATUS_OK);
}
@Test
@Feature({"Omaha"})
public void testValidNoUpdatecheck() throws RequestFailureException {
runSuccessTest(APP_STATUS_OK, true, true, null);
}
@Test
@Feature({"Omaha"})
public void testValidUpdatecheckNoUpdate() throws RequestFailureException {
runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_NOUPDATE);
}
@Test
@Feature({"Omaha"})
public void testValidUpdatecheckError() throws RequestFailureException {
runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_ERROR);
}
@Test
@Feature({"Omaha"})
public void testValidUpdatecheckUnknown() throws RequestFailureException {
runSuccessTest(APP_STATUS_OK, false, false, UPDATE_STATUS_WTF);
}
@Test
@Feature({"Omaha"})
public void testValidAppStatusRestricted() throws RequestFailureException {
runSuccessTest(APP_STATUS_RESTRICTED, false, false, null);
}
@Test
@Feature({"Omaha"})
public void testFailBogusResponse() {
String xml = "Bogus";
runFailureTest(xml, RequestFailureException.ERROR_MALFORMED_XML, false, false, false);
}
@Test
@Feature({"Omaha"})
public void testBadResponseProtocol() {
String xml =
createTestXML("2.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_RESPONSE, false, false, false);
}
@Test
@Feature({"Omaha"})
public void testFailMissingDaystart() {
String xml =
createTestXML("3.0", null, APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_DAYSTART, false, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagMissingUpdatecheck() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, true, false, null, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, true, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagUnexpectedUpdatecheck() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, true, false, false);
}
@Test
@Feature({"Omaha"})
public void testAppTagMissingPing() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, true, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagUnexpectedPing() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, false, true, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagMissingInstall() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, true, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagUnexpectedInstall() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, false, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagStatusError() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_ERROR, false, false, null, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_APP, false, false, false);
}
@Test
@Feature({"Omaha"})
public void testUpdatecheckMissingUrl() {
String xml = createTestXML(
"3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, null);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_URLS, false, false, true);
}
}
......@@ -2926,6 +2926,26 @@
},
'includes': [ '../build/java_apk.gypi' ],
},
{
# GN: //chrome/android:chrome_shell_unit_tests
'target_name': 'chrome_shell_unit_tests',
'type': 'none',
'dependencies': [
'chrome_java',
'../base/base.gyp:base',
'../base/base.gyp:base_java_test_support',
'../testing/android/junit/junit_test.gyp:junit_test_support',
],
'variables': {
'main_class': 'org.chromium.testing.local.JunitTestMain',
'src_paths': [
'android/junit/',
],
},
'includes': [
'../build/host_jar.gypi',
],
},
{
# GN: //chrome/test/chromedriver/test/webview_shell:chromedriver_webview_shell_apk
'target_name': 'chromedriver_webview_shell_apk',
......
......@@ -2026,6 +2026,26 @@
},
'includes': [ '../build/java_apk.gypi' ],
},
{
# GN: //content/public/android:content_shell_unit_tests
'target_name': 'content_shell_unit_tests',
'type': 'none',
'dependencies': [
'content.gyp:content_java',
'../base/base.gyp:base_java',
'../base/base.gyp:base_java_test_support',
'../testing/android/junit/junit_test.gyp:junit_test_support',
],
'variables': {
'main_class': 'org.chromium.testing.local.JunitTestMain',
'src_paths': [
'public/android/junit/',
],
},
'includes': [
'../build/host_jar.gypi',
],
},
],
}],
['OS!="android" and OS!="ios" and OS!="linux"', {
......
......@@ -178,4 +178,17 @@ android_library("content_javatests") {
DEPRECATED_java_in_dir = "javatests/src"
}
# GYP: //content/content_tests.gypi:content_shell_unit_tests
java_binary("chrome_shell_unit_tests") {
testonly = true
java_files = [ "junit/src/org/chromium/content/browser/input/GamepadMappingsTest.java" ]
main_class = "org.chromium.testing.local.JunitTestMain"
deps = [
":content_java",
"//base:base_java",
"//base:base_java_test_support",
"//testing/android/junit:junit_test_support",
]
}
# TODO(GYP): content_icudata
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser.input;
import android.view.KeyEvent;
import android.view.MotionEvent;
import org.chromium.base.test.util.Feature;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import java.util.Arrays;
import java.util.BitSet;
/**
* Verify no regressions in gamepad mappings.
*/
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class GamepadMappingsTest {
private static final float ERROR_TOLERANCE = 0.000001f;
/**
* Set bits indicate that we don't expect the button at mMappedButtons[index] to be mapped.
*/
private BitSet mUnmappedButtons = new BitSet(CanonicalButtonIndex.COUNT);
/**
* Set bits indicate that we don't expect the axis at mMappedAxes[index] to be mapped.
*/
private BitSet mUnmappedAxes = new BitSet(CanonicalAxisIndex.COUNT);
private float[] mMappedButtons = new float[CanonicalButtonIndex.COUNT];
private float[] mMappedAxes = new float[CanonicalAxisIndex.COUNT];
private float[] mRawButtons = new float[GamepadDevice.MAX_RAW_BUTTON_VALUES];
private float[] mRawAxes = new float[GamepadDevice.MAX_RAW_AXIS_VALUES];
@Before
public void setUp() throws Exception {
// By default, we expect every button and axis to be mapped.
mUnmappedButtons.clear();
mUnmappedAxes.clear();
// Start with all the mapped values as unmapped.
Arrays.fill(mMappedButtons, Float.NaN);
Arrays.fill(mMappedAxes, Float.NaN);
// Set each raw value to something unique.
for (int i = 0; i < GamepadDevice.MAX_RAW_AXIS_VALUES; i++) {
mRawAxes[i] = -i - 1.0f;
}
for (int i = 0; i < GamepadDevice.MAX_RAW_BUTTON_VALUES; i++) {
mRawButtons[i] = i + 1.0f;
}
}
@Test
@Feature({"Gamepad"})
public void testShieldGamepadMappings() throws Exception {
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons,
GamepadMappings.NVIDIA_SHIELD_DEVICE_NAME_PREFIX);
assertShieldGamepadMappings();
}
@Test
@Feature({"Gamepad"})
public void testXBox360GamepadMappings() throws Exception {
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons,
GamepadMappings.MICROSOFT_XBOX_PAD_DEVICE_NAME);
assertShieldGamepadMappings();
}
@Test
@Feature({"Gamepad"})
public void testPS3SixAxisGamepadMappings() throws Exception {
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons,
GamepadMappings.PS3_SIXAXIS_DEVICE_NAME);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_X], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_A], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_B], ERROR_TOLERANCE);
assertMappedCommonTriggerButtons();
assertMappedCommonThumbstickButtons();
assertMappedCommonDpadButtons();
assertMappedCommonStartSelectMetaButtons();
assertMappedTriggerAxexToShoulderButtons();
assertMappedXYAxes();
assertMappedZAndRZAxesToRightStick();
assertMapping();
}
@Test
@Feature({"Gamepad"})
public void testSamsungEIGP20GamepadMappings() throws Exception {
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons,
GamepadMappings.SAMSUNG_EI_GP20_DEVICE_NAME);
assertMappedCommonXYABButtons();
assertMappedCommonTriggerButtons();
assertMappedCommonThumbstickButtons();
assertMappedCommonStartSelectMetaButtons();
assertMappedHatAxisToDpadButtons();
assertMappedXYAxes();
assertMappedRXAndRYAxesToRightStick();
expectNoShoulderButtons();
assertMapping();
}
@Test
@Feature({"Gamepad"})
public void testAmazonFireGamepadMappings() throws Exception {
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons,
GamepadMappings.AMAZON_FIRE_DEVICE_NAME);
assertMappedCommonXYABButtons();
assertMappedPedalAxesToBottomShoulder();
assertMappedCommonThumbstickButtons();
assertMappedCommonStartSelectMetaButtons();
assertMappedTriggerButtonsToTopShoulder();
assertMappedHatAxisToDpadButtons();
assertMappedXYAxes();
assertMappedZAndRZAxesToRightStick();
assertMapping();
}
@Test
@Feature({"Gamepad"})
public void testUnknownGamepadMappings() throws Exception {
GamepadMappings.mapToStandardGamepad(
mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, "");
assertMappedCommonXYABButtons();
assertMappedCommonTriggerButtons();
assertMappedCommonThumbstickButtons();
assertMappedCommonStartSelectMetaButtons();
assertMappedTriggerAxexToShoulderButtons();
assertMappedCommonDpadButtons();
assertMappedXYAxes();
assertMappedRXAndRYAxesToRightStick();
assertMapping();
}
/**
* Asserts that the current gamepad mapping being tested matches the shield mappings.
*/
public void assertShieldGamepadMappings() {
assertMappedCommonXYABButtons();
assertMappedTriggerButtonsToTopShoulder();
assertMappedCommonThumbstickButtons();
assertMappedCommonStartSelectMetaButtons();
assertMappedTriggerAxesToBottomShoulder();
assertMappedHatAxisToDpadButtons();
assertMappedXYAxes();
assertMappedZAndRZAxesToRightStick();
assertMapping();
}
public void expectNoShoulderButtons() {
mUnmappedButtons.set(CanonicalButtonIndex.LEFT_SHOULDER);
mUnmappedButtons.set(CanonicalButtonIndex.RIGHT_SHOULDER);
}
public void assertMapping() {
for (int i = 0; i < mMappedAxes.length; i++) {
if (mUnmappedAxes.get(i)) {
Assert.assertTrue(
"An unexpected axis was mapped at index " + i, Float.isNaN(mMappedAxes[i]));
} else {
Assert.assertFalse(
"An axis was not mapped at index " + i, Float.isNaN(mMappedAxes[i]));
}
}
for (int i = 0; i < mMappedButtons.length; i++) {
if (mUnmappedButtons.get(i)) {
Assert.assertTrue("An unexpected button was mapped at index " + i,
Float.isNaN(mMappedButtons[i]));
} else {
Assert.assertFalse(
"A button was not mapped at index " + i, Float.isNaN(mMappedButtons[i]));
}
}
}
private void assertMappedCommonTriggerButtons() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], ERROR_TOLERANCE);
}
private void assertMappedCommonDpadButtons() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN],
mRawButtons[KeyEvent.KEYCODE_DPAD_DOWN], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP],
mRawButtons[KeyEvent.KEYCODE_DPAD_UP], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_LEFT],
mRawButtons[KeyEvent.KEYCODE_DPAD_LEFT], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT],
mRawButtons[KeyEvent.KEYCODE_DPAD_RIGHT], ERROR_TOLERANCE);
}
private void assertMappedTriggerAxexToShoulderButtons() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER],
mRawAxes[MotionEvent.AXIS_LTRIGGER], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER],
mRawAxes[MotionEvent.AXIS_RTRIGGER], ERROR_TOLERANCE);
}
private void assertMappedTriggerButtonsToTopShoulder() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER],
mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], ERROR_TOLERANCE);
}
private void assertMappedCommonXYABButtons() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_A], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_B], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_X], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY],
mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], ERROR_TOLERANCE);
}
private void assertMappedCommonThumbstickButtons() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_THUMBSTICK],
mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK],
mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR], ERROR_TOLERANCE);
}
private void assertMappedCommonStartSelectMetaButtons() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.START],
mRawButtons[KeyEvent.KEYCODE_BUTTON_START], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.BACK_SELECT],
mRawButtons[KeyEvent.KEYCODE_BUTTON_SELECT], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.META],
mRawButtons[KeyEvent.KEYCODE_BUTTON_MODE], ERROR_TOLERANCE);
}
private void assertMappedPedalAxesToBottomShoulder() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER],
mRawAxes[MotionEvent.AXIS_BRAKE], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER],
mRawAxes[MotionEvent.AXIS_GAS], ERROR_TOLERANCE);
}
private void assertMappedTriggerAxesToBottomShoulder() {
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER],
mRawAxes[MotionEvent.AXIS_LTRIGGER], ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER],
mRawAxes[MotionEvent.AXIS_RTRIGGER], ERROR_TOLERANCE);
}
private void assertMappedHatAxisToDpadButtons() {
float hatX = mRawAxes[MotionEvent.AXIS_HAT_X];
float hatY = mRawAxes[MotionEvent.AXIS_HAT_Y];
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_LEFT],
GamepadMappings.negativeAxisValueAsButton(hatX), ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT],
GamepadMappings.positiveAxisValueAsButton(hatX), ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP],
GamepadMappings.negativeAxisValueAsButton(hatY), ERROR_TOLERANCE);
Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN],
GamepadMappings.positiveAxisValueAsButton(hatY), ERROR_TOLERANCE);
}
private void assertMappedXYAxes() {
Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_X],
mRawAxes[MotionEvent.AXIS_X], ERROR_TOLERANCE);
Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_Y],
mRawAxes[MotionEvent.AXIS_Y], ERROR_TOLERANCE);
}
private void assertMappedRXAndRYAxesToRightStick() {
Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X],
mRawAxes[MotionEvent.AXIS_RX], ERROR_TOLERANCE);
Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y],
mRawAxes[MotionEvent.AXIS_RY], ERROR_TOLERANCE);
}
private void assertMappedZAndRZAxesToRightStick() {
Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X],
mRawAxes[MotionEvent.AXIS_Z], ERROR_TOLERANCE);
Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y],
mRawAxes[MotionEvent.AXIS_RZ], ERROR_TOLERANCE);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment